What the purpose of OnModelCreating in EF4 Code-First?

限于喜欢 提交于 2019-12-03 06:53:19

问题


I was curious about what the purpose of OnModelCreating in EF4 Code-First context class? How does it work?


回答1:


Here is a nice article in ADO.NET Team Blog.
In short, this event is mainly for Fluent mapping.




回答2:


OnModelCreating gives you access to a ModelBuilder instance that you can use to configure/customize the model.

As the previous answer mentions, you will typically use the code-first fluent API within it. Gil Fink has posted what IMHO is a clearer explanation than the article cited in the previous answer.

For background info, Guthrie has a nice intro article on EF Code-First, and if you are wondering why its referred to as "fluent API", look here.



来源:https://stackoverflow.com/questions/4759004/what-the-purpose-of-onmodelcreating-in-ef4-code-first

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!