Cizaphil Cizaphil - 2 years ago 88
C# Question

Can I create a poco class with private setter in EntityFramework

What am trying to achieve is to create a class as shown below.

public class Purse
public decimal AvaliableBalance { get; protected set; }
public decimal PendingBalance { get; protected set; }
public decimal TotalBalance { get; protected set; }

But am wondering if entity framework will be able to populate this class. If so, how?

Basically what am trying to accomplish is to restrict writing directly to these properties on the code side but i want Entity framework to be able to write to this properties.I want to expose the setter of these properties through a method whose sole purpose is to write values to it (ie: after some processing of course).

Answer Source

Your approach will work. I have used this pattern heavily. Entity Framework uses reflection to materialize your data into objects. Since reflection will work happily even if your members are private, the pattern works well.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download