これは、DTOへのマッピングに問題があります。以下のコード、およびその作業罰金を使用してIMをViewModelにするDTOからマッピング用ViewModelからDTOに戻ってマッピングするときのAutoMapperの問題
public class BusinessEntity
{
public ChildBussiness Details { get; set; }
}
public class ChildBussiness
{
public string NameFirst { get; set; }
public string LastName { get; set; }
public Books BookDetails { get; set; }
public string Salary { get; set; }
}
public class Books
{
public string BookName { get; set; }
public int BookPrice { get; set; }
public string BookDescription { get; set; }
}
コントローラ
:
DTO:
public class ServiceEntity : BaseChild
{
public int Id { get; set; }
}
public class BaseChild
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Salary { get; set; }
public string BkName { get; set; }
public int BkPrice { get; set; }
public string BkDescription { get; set; }
}
ビューモデル。
public ActionResult Index()
{
ServiceEntity obj = GetData();
Mapper.CreateMap<ServiceEntity, BusinessEntity>()
.ForMember(d => d.Details, o => o.MapFrom(x => new ChildBussiness { NameFirst = x.FirstName, LastName = x.LastName, Salary = x.Salary.ToString(), BookDetails = new Books { BookDescription = x.BkDescription, BookName = x.BkName, BookPrice = x.BkPrice }}));
BusinessEntity objDetails = Mapper.Map<ServiceEntity, BusinessEntity>(obj);
}
逆変換できません。以下のコードを試してみました。
.
.
.
ServiceEntity objser = new ServiceEntity();
Mapper.CreateMap<BusinessEntity, ServiceEntity>();
Mapper.CreateMap<Books, ServiceEntity>();
objser = Mapper.Map<BusinessEntity, ServiceEntity>(model);
.
.
.
しかし、私は成功しませんでした。私はいくつかのプロパティを提供しています。私はリアルタイムで私は30以上の財産を持つかもしれません。 任意の提案はこのようにあなたがAutoMapper規則及び平坦化のパワーを使用することができ、BusinessEntity
実装を変更することができます...
エラーが発生しているのか、空のプロパティだけがありますか? –