In EF Code First, can you encapsulate the properties that should be stored in the data warehouse?

So let's say I have POCO that I want EF Code First to be stored in the data store:

public class Campaign
{
    public string Name { get; set; }
    public double GoalAmount { get; set; }
    private double AmountRaised { get; set; }
    public bool GoalMet
    {
        get
        {
            return AmountRaised >= GoalAmount;
        }
    }
}

Now, for some reason, I do not want the property to AmountRaisedbe accessible outside the object, but I want it to be stored in the data store. Is this possible with the first EF code?

+1
source share
1 answer

You can do it internaland make sure that the project containing the POCOs / domain objects is in the same assembly as your classes DbContext. Or you can declare friend assemblies in files containing your POCOs:

[assembly: InternalsVisibleTo("MyOther.Assembly")]

+5
source

Source: https://habr.com/ru/post/1791990/


All Articles