Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity framework, POCO and a private property

I've created the following POCO class and also made Contact.FirstName and Contact.LastName properties private ( these properties are mapped to appropriate properties in an Entity Framework model ).

public class Contact
{
    public int ContactID { get; set; }
    private string FirstName { get; set; }
    public string LastName { get; private set; }
}

I expected to get an exception due to EF not being able to assign values to these two properties, but somehow EF still managed to assign values to them. How is that possible, since only code in Contact class should have accesses to private properties?

Thank you

like image 535
user702769 Avatar asked Apr 12 '12 17:04

user702769


1 Answers

In environments with sufficient levels of trust, reflection can be used to access members to which one would not normally have access.

like image 17
Kent Boogaart Avatar answered Nov 07 '22 01:11

Kent Boogaart