Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map a protected property in EF 4.3 code first

In EF 4.3 documentation says:

By default, building a database using Code First does not include private, protected, or internal properties. If you manually included these properties in your model, Code First would ignore any data annotations on those members. This is issue now fixed, and Code First processes the data annotations.

My question is how to included a protected property manully with code first, espically using fluent API?

like image 898
Smartkid Avatar asked Feb 16 '12 13:02

Smartkid


2 Answers

Look at http://blog.cincura.net/232147-mapping-private-or-protected-properties-with-code-first-efv4-ctp4/ to the comment from Drew Jones. Not entirely clean, but at least something. :)

Or directly http://blog.cincura.net/232731-mapping-private-protected-properties-in-entity-framework-4-x-code-first/.

like image 112
cincura.net Avatar answered Oct 15 '22 12:10

cincura.net


It is not possible with fluent API because fluent API uses strongly typed approach and because of that all accessibility rules are still in place. Documentation says it should be possible with data annotations but I wasn't able to make it work.

like image 42
Ladislav Mrnka Avatar answered Oct 15 '22 11:10

Ladislav Mrnka