0
我在VB中有以下源代码类。为什么AutoMapper不能映射这些嵌套集合?
Public Class Product
...
Public Property itemizedSize As Size()
Get
Return _arrItemizedSizes
End Get
Set(ByVal value As Size())
_arrItemizedSizes = value
End Set
End Property
...
End Class
Public Class Size
Private _strName As String
Private _intQuantity As Integer
Private _intScale As Integer
Public Property name() As String
Get
Return _strName
End Get
Set(ByVal value As String)
_strName = value
End Set
End Property
Public Property quantity() As Integer
Get
Return _intQuantity
End Get
Set(ByVal value As Integer)
_intQuantity = value
End Set
End Property
Public Property Scale() As Integer
Get
Return _intScale
End Get
Set(ByVal value As Integer)
_intScale = value
End Set
End Property
Public Sub New()
_strName = ""
_intQuantity = 0
_intScale = 0
End Sub
Public Sub New(ByVal name As String, ByVal quantity As Integer, Optional ByVal Scale As Integer = 0)
_strName = name
_intQuantity = quantity
_intScale = Scale
End Sub
End Class
,我试图
public class ProductsViewModel : List<ProductViewModel>
{
...
}
public class ProductViewModel
{
...
public SizeViewModel[] ItemizedSize { get; set; }
...
}
public class SizeViewModel
{
public string Name { get; set; }
public int Quantity { get; set; }
}
我使用下面的代码做我的映射将其映射到这些C#类......不过,我得到一个异常说,映射不定义从尺寸到尺寸查看模型
AutoMapper.Mapper.CreateMap<Size, SizeViewModel>();
AutoMapper.Mapper.CreateMap<Product, ProductViewModel>();
ProductsViewModel model = AutoMapper.Mapper.Map<List<Product>, ProductsViewModel>(productDetails);
AutoMapper.Mapper.AssertConfigurationIsValid();
有什么,我失踪了?任何帮助将不胜感激..谢谢!
.Net有班级规模。改变你班级的名字。也许它工作。 – 2012-08-15 01:14:15
好点 - 将鼠标悬停在VS中的Size上,看看你得到的是什么名字空间... automapper并不在乎什么类型被映射,但你确实:) – Charleh 2012-08-15 09:55:55
是的,我想过...它是Size类在我的名字空间 – ntsue 2012-08-15 11:29:56