What is modelBuilder.entity(Of x)

c# ef-code-first entity-framework-6 vb.net

Question

I have a context class for an EF 6 project that has the following modelBuilder properties for each column in each table:

Protected Overrides Sub OnModelCreating(ByVal modelBuilder As DbModelBuilder)
    modelBuilder.Entity(Of Product)() _
        .Property(Function(e) e.Name) _
        .IsUnicode(False)

    modelBuilder.Entity(Of Product)() _
        .Property(Function(e) e.Description) _
        .IsUnicode(False)
End Sub

What is this for? In database first or even code first examples I have not seen this. This context class was created with 'code first existing database'. I'm new to EF and would like to understand what this is present for.

Thanks-

1
0
3/7/2015 7:51:02 AM

Accepted Answer

When using Code First your model is calculated from your classes using a set of conventions. The default Code First Conventions determine things like which property becomes the primary key of an entity, the name of the table an entity maps to, and what precision and scale a decimal column has by default.

Sometimes these default conventions are not ideal for your model, and you have to work around them by configuring many individual entities using Data Annotations or the Fluent API. Custom Code First Conventions let you define your own conventions that provide configuration defaults for your model.

Read more here...

https://msdn.microsoft.com/en-us/data/jj819164.aspx

Nice article as well...

http://www.codeproject.com/Articles/165720/Using-the-Code-First-Model-Configuration-Classes

1
12/15/2019 3:30:32 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow