Friday, February 20, 2015

Entity Framework works fine with private / internal / protected properties

This was probably just me, but I was always under the impression the EF had a hard time hydrating objects with private or protected access modifiers. Turns out not to be the case, at least not in EF 6.

I was looking around for solutions, but noticed that all solutions to - what I thought was a - problem, were pretty old. So I wrote a quick test to see how EF behaves nowadays.

Turns out: any access modifier can be hydrated from EF - no problem.

Here's my model:

Here's the roundtrip test - as you can see - the person coming from the database has all the properties set as expected:

Just for visual verification: everything is nicely in the DB. Although that's not what I was worried about.

Wow - I feel like a n00b not knowing this before.

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru Dot Net Training in Chennai. Nowadays Dot Net has tons of job opportunities on various vertical industry.
    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.