I was curious about what the purpose of OnModelCreating in EF4 Code-First context class? How does it work?
相关问题
- Entity Framework Code First Migration
- Entity Framework throws exception - Network Relate
- How to Specify a Compound key in Entity Framework
- Slow loading first page - ASP.NET MVC
- query and create objects with a one to many relati
相关文章
-
EF6 DbSet
returns null in Moq - Entity Framework 4.3.1 failing to create (/open) a
- EF6 code first: How to load DbCompiledModel from E
- Why do I need a ToList() to avoid disposed context
- Code-First Add-Migration keeps adding the same col
- EF Codefirst validate unique property?
- EF Core 'another instance is already being tra
- Add XML documentation / comments to properties/fie
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.
Here is a nice article in ADO.NET Team Blog.
In short, this event is mainly for Fluent mapping.