对我来说问题是我的数据库中有一个现有的数据表“T_store”,包含3个字段:storeKey,StoreName,StoreDescription。而我现在想要创建一个MVC 3应用程序。为了映射到所有这个领域,我有
public int Id {get; }{set;}
public int storeKey {get; }{set;}
public int StoreName {get; }{set;}
public int StoreDescription {get; }{set;}
但是如果我声明了int id,我收到了一个错误,因为现有的数据表没有这个字段?
请提出任何想法
答案 0 :(得分:2)
如果您想要实体和表格中的ID,请在表格中创建ID列。如果只想在实体中使用ID,请使用[NotMapped]作为ID属性。此外,我猜您将使用storeKey
作为您实体的密钥,因此您应该在此媒体资源上使用[Key]
。
答案 1 :(得分:1)
我想知道为什么你需要Id属性,因为你的表已经有一个关键列,但我认为这将解决你的问题:
[NotMapped]
public int Id { get; set; }
[Key]
public int storeKey { get; set; }
public int StoreName { get; set; }
public int StoreDescription { get; set; }