-1

我有一个 varchar 键列。我正在尝试使用GetDapper contrib 的方法。我得到一个例外:

Get 仅支持具有 [Key] 或 [ExplicitKey] 属性的实体。

我的实体:

public class State : BaseModel
{
    [Key]       
    public string state_code { get; set; }
    public string state_name { get; set; }
    public int language_code { get; set; }
    public bool is_active { get; set; }
}

我的精巧方法

public IEnumerable<State> FindByCode(string code)
{
    return this._db.Get<State>(code);
}

我什至尝试设置显式密钥,但仍然出现相同的错误。我究竟做错了什么?

4

1 回答 1

2

尝试检查您的代码,例如:

public class State : BaseModel
{
    [System.ComponentModel.DataAnnotations.Key]
    [Dapper.Contrib.Extensions.Key]
    public string state_code { get; set; }
    public string state_name { get; set; }
    public int language_code { get; set; }
    public bool is_active { get; set; }
}
于 2019-08-28T07:33:57.593 回答