问题描述:

The problem for me is I have an existing datatable "T_store" in my database with 3 field: storeKey, StoreName, StoreDescription. and I now I want to create a MVC 3 app. to map to all this field, I have

public int Id {get; }{set;}

public int storeKey {get; }{set;}

public int StoreName {get; }{set;}

public int StoreDescription {get; }{set;}

but I got an error if I declare int id, since the existing datatable doesnt have this field ?

any ideas please

网友答案:

If you want the ID in the entity and in the table, create the ID column in the table. If you want ID only in the entity, use [NotMapped] for the ID property. Also, I guess that you will use storeKey as the key for your entity, so you should use [Key] on this property.

网友答案:

I wonder why you need Id property as your table already has a key column but, I think this will resolve your problem :

[NotMapped]
public int Id { get; set; }
[Key]
public int storeKey { get; set; }
public int StoreName { get; set; }
public int StoreDescription { get; set; }
相关阅读:
Top