亚音简单存储库 - 坚持私有财产
-
30-09-2019 - |
题
我正在利用亚音速简称
我有一堂课:
public class X{public string abc {get; set;}private string def {get; set;}}
属性“ def”仅在该类中设置,我不希望该属性在外部可见,但是由于某种原因,当我使用repo.save(x)保存对象时,私有属性不持续到DB
有帮助吗?
解决方案
设置两个数据模型,一个在前端(公共,可见)中代表X,一个代表后端(私有,隐藏)中代表X的数据模型:
namespace App.BackEnd // classes here are used for database storage
{
public class X
{
public string abc { get; set; }
public string def { get; set; }
public FrontEnd.X ToFrontEnd()
{
return new FrontEnd.X
{
abc = abc
};
}
}
}
namespace App.FrontEnd // classes here are used for public interfaces
{
public class X
{
public string abc { get; set; }
}
}
不隶属于 StackOverflow