我正在尝试将模型映射到实体对象,但是当我映射从 DB 接收到的实体对象时 - 我的更改不会保存在数据库中。
这是一些代码:
映射配置:
Mapper.CreateMap<WalletUpdateModel, Wallet>()
.ForMember(o => o.Name, m => m.MapFrom(d => d.Name))
.ForMember(o => o.Currency, m => m.MapFrom(d => d.Currency));
实体对象:
public partial class Wallet
{
public Wallet()
{
this.Transactions = new HashSet<Transaction>();
}
public int Id { get; set; }
public int Owner { get; set; }
public string Name { get; set; }
public string Currency { get; set; }
public virtual ICollection<Transaction> Transactions { get; set; }
}
型号声明:
public class WalletUpdateModel
{
[Required]
[Range(1, int.MaxValue)]
public int Id { get; set; }
[Required]
[MaxLength(128)]
public string Name { get; set; }
[Required]
[MaxLength(3)]
[DataType(DataType.Currency)]
public string Currency { get; set; }
}
以及来自即时窗口的一些调试信息:
w (before mapping)
{System.Data.Entity.DynamicProxies.Wallet_E3CA830BB5384920A3E07D4B44F15D2409093A34BFCED7CA33F9EC4102445554}
[System.Data.Entity.DynamicProxies.Wallet_E3CA830BB5384920A3E07D4B44F15D2409093A34BFCED7CA33F9EC4102445554]: {System.Data.Entity.DynamicProxies.Wallet_E3CA830BB5384920A3E07D4B44F15D2409093A34BFCED7CA33F9EC4102445554}
Currency: "PLN"
Id: 2
Name: "Cash"
Owner: 1
Transactions: Count = 0
w (after mapping)
{Financica.WebServices.Wallet}
Currency: "PLN"
Id: 2
Name: "BZWBK"
Owner: 0
Transactions: Count = 0
请帮我解决这个问题,谢谢。