另一种选择是将属性包装在同一类中的非生成属性中。不理想,因为您最终可能会拥有双重属性,但如果您可以让生成器生成受保护的属性,那将是一个非常好的方法。
只需要处理这个问题:实体框架生成类,我想用更简单的名称将它们序列化为 JSON。
// GENERATED BY EF
public partial class ti_Users
{
public ti_Users()
{
this.ti_CardData = new HashSet<ti_CardData>();
this.ti_Orders = new HashSet<ti_Orders>();
}
protected int userId { get; set; }
protected string userName { get; set; }
protected string userEmail { get; set; }
protected string userPassHash { get; set; }
protected Nullable<System.DateTime> userLastLogin { get; set; }
protected string userLastIP { get; set; }
public virtual ICollection<ti_CardData> ti_CardData { get; set; }
public virtual ICollection<ti_Orders> ti_Orders { get; set; }
}
和附加类:
[JsonObject(memberSerialization: MemberSerialization.OptIn)]
public partial class ti_Users
{
[JsonProperty]
public int UserId
{
get { return this.userId; }
set { this.userId = value; }
}
[JsonProperty]
public string Name
{
get { return this.userName; }
set { this.userName = value; }
}
[JsonProperty]
public string Email
{
get { return this.userEmail; }
set { this.userEmail = value; }
}
[JsonProperty]
public string PassHash
{
get { return this.userPassHash; }
set { this.userPassHash = value; }
}
}