当尝试在属性位于继承对象中的对象中使用 Contrib 的 CRUD 方法时,我得到一个
实体必须至少有一个 [Key] 或 [ExplicitKey] 属性
错误。这是我的对象的简化版本:
public class BaseObject
{
public string Delete()
{
using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString))
{
db.Delete(this);
}
}
}
和这个
public class Product: BaseObject
{
[Key]
public int id { get; set; }
public string title { get; set; }
public string name { get; set; }
}
执行时出现错误:
Product product = new Product() {id = 1};
product.Delete();
如果我删除继承并将 Delete() 方法移动到 Product 对象中,它可以完美地工作。
有任何想法吗?