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")]
精彩评论