简体   繁体   中英

Entity Framework Code First: Custom Mapping Using Attribute?

In ScottGu's article , he uses OnModelCreating method to define schema mapping. I am wondering if Entity Framework has some existing feature that allows us to do the mapping through attribute. For example, the Dinner class mentioned in that article could be like:

[MapTable="tblDinner"]
public class Dinner{
  [MapColumn="colId"]
  public int DinnerID {get;set;}
}

Absolutely. See 'Table' and 'Column' attributes in: http://msdn.microsoft.com/en-us/data/gg193958

I think you are looking for 'Data Annotations' Check the following blog for more info: Data Annotations in the Entity Framework and Code First

They allow you to place attributes in your source code that will tell the Entity Framework how to do the mapping

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM