【发布时间】:2016-11-25 23:07:29
【问题描述】:
[DataContract]
public class SupplierView : BaseView
{
[DataMember]
Public int SupplierId { get; set; }
[DataMember]
Public ApprovedSupplierView approvedSupplier { get; set; }
[DataMember]
Public AdHocSupplierView adhocsupplier { get; set; }
//other fields...
}
[DataContract]
public class ContextSupplierView : SupplierView //Working
{
[DataMember]
Public int SupplierId { get; set; }
//New fields added
[DataMember]
Public ContextApprovedSupplierView contextApprovedSupplier { get; set; }
[DataMember]
Public ContextAdHocSupplierView contextAdhocsupplier { get; set; }
//other fields...
}
public class ApprovedSupplierView : BaseView
{
[DataMember]
Public string Name { get; set; }
[DataMember]
Public string Phone { get; set; }
[DataContract]
public class ContextSupplierView : SupplierView //Not working
{
[DataMember]
Public int SupplierId { get; set; }
[DataMember]
Public new ContextApprovedSupplierView approvedSupplier { get; set; }
[DataMember]
Public new ContextAdHocSupplierView adhocsupplier { get; set; }
//other fields...
}
[DataContract]
public class ContextApprovedSupplierView : ApprovedSupplierView
{
[DataMember]
Public string ContextDescription { get; set; }
SupplierView supplierObject = new SupplierView(Linq populates this correctly);
Mapper.CreateMap<SupplierView, ContextSupplierView>();
claimContext.Supplier = Mapper.Map<ContextSupplierView>(supplierObject);
我有一个项目,它已经从数据库中获取了供应商及其嵌套类型,但是我如何使用 automapper 将所有内容复制到具有 ContextApprovedSupplier 和 ContextAdHocSupplier adHocSupplier 的 ContextSupplier 中,但这给出了:
缺少类型映射配置或不支持的映射。
映射类型:ApprovedSupplierView -> ContextApprovedSupplierView TotalSystemsPlc.Bluescape.Claims.DataContracts.Views.ProjectLoadViews.ApprovedSupplierView -> TotalSystemsPlc.Bluescape.Claims.DataContracts.Views.ContextViews.ContextApprovedSupplierView
目标路径: ContextSupplierView.ApprovedSupplier.ApprovedSupplier
来源价值: TotalSystemsPlc.Bluescape.Claims.DataContracts.Views.ProjectLoadViews.ApprovedSupplierView
如果我创建新字段 contextApprovedSupplier 和 contextAdhocsupplier,它会自动填充 ApprovedSupplier 和 Adhocsupplier,它们可以单独映射,但我宁愿在一个命令中完成所有操作。 由于我已经尝试了几个小时来做这件事,任何帮助都会得到很大的帮助!!!
编辑:抱歉,请立即找到正确的层次结构!
【问题讨论】:
-
SupplierView和ContextSupplierView是什么? -
不应该从
ContextSupplier派生Supplier吗?如果不是,则提供声明隐藏属性的Base类approvedSupplieradhocsupplier -
您可以尝试添加映射:
Mapper.CreateMap<ApprovedSupplierView, ContextApprovedSupplier>()但在这种情况下您的视图不应该返回ContextApprovedSupplierView吗? -
@Rafal - 是的,我希望原始类映射到派生类
-
@AndrewDay 能回答你的问题吗?
标签: c# model-view-controller automapper