Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 4.1 Code First: How is the Discriminator determined?

Currently I have class hierarchy defined with the Code First approach as follows.

enter image description here

E.F. has autogenerated a nvarchar(128) discriminator. It is not a key field.

How does Entity Framework determine what and what Type the discriminator field should be, and is it always the same, i.e. nvarchar? Is the discriminator at all accessible outside the database i.e. from LINQ to Entity?

like image 513
T. Webster Avatar asked Feb 26 '26 00:02

T. Webster


1 Answers

Discriminator column is by default nvarchar because it stores names of your classes to differ between types - that is the whole point of this column: to allow EF knowing what class instance from your inheritance hierarchy it should create when it loads record from the database.

Discriminator column is not accessible by linq-to-entities. It is only used to map record to correct type.

like image 165
Ladislav Mrnka Avatar answered Feb 28 '26 21:02

Ladislav Mrnka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!