开发者

In EF Code First is it possible to encapsulate properties that should be persisted to the data store?

So let's say I've got a POCO that I want EF Code First to persist to a data store:

public class Campaign
{
    public string Name { get; 开发者_Go百科set; }
    public double GoalAmount { get; set; }
    private double AmountRaised { get; set; }
    public bool GoalMet
    {
        get
        {
            return AmountRaised >= GoalAmount;
        }
    }
}

Now, for whatever reason, I don't want the AmountRaised property to be accessible outside the object, but I do want it persisted to the data store. Is this possible with EF Code First?


You can make it internal and make sure that the project that contains the POCOs / domain objects are in the same assembly as your DbContext classes. Or you can declare "friend" assemblies in the files that contain your POCOs:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜