EF Code-First to Existing Database
-
Hello all, I have applied EF Code-First to Existing Database like this : 1- Created an ADO.NET Entity Data Model 2- Chose Code First from Database All of the classes generated correctly, except there are a lot of [Key] tags before most of the properties. Should I remove them from unnecessary ones? Another question is, how can I be sure that EF kept the one-to-many or many-to-many relationships? There is nothing like :
public virtual ICollection Posts { get; set; }
Thanks in advance.
-
Hello all, I have applied EF Code-First to Existing Database like this : 1- Created an ADO.NET Entity Data Model 2- Chose Code First from Database All of the classes generated correctly, except there are a lot of [Key] tags before most of the properties. Should I remove them from unnecessary ones? Another question is, how can I be sure that EF kept the one-to-many or many-to-many relationships? There is nothing like :
public virtual ICollection Posts { get; set; }
Thanks in advance.
(...) there are a lot of [Key] tags before most of the properties. Should I remove them from unnecessary ones? No. You sohuldn't change anything unless you're really shure what you're doing. Please, see: Working with Entity Keys[^] Entity Framework (EF) Documentation[^] An .edmx file[^] Data Points: Code First Goodies in Entity Framework 6[^]