使用Automapper映射到CSLA对象
|
我正在尝试将DTO对象映射到CSLA.NET(请参阅:http://www.lhotka.net/cslanet/)对象。为了这个问题,我正在使用Lhotka随其框架提供的示例应用程序。下面是我正在使用的类的示例(为清楚起见,我删除了大多数属性和方法):
<Serializable()> _
Public Class Project
Inherits BusinessBase(Of Project)
Private mId As Guid = Guid.NewGuid
Private mName As String = \"\"
Private mResources As ProjectResources = _
ProjectResources.NewProjectResources()
<System.ComponentModel.DataObjectField(True, True)> _
Public ReadOnly Property Id() As Guid
<System.Runtime.CompilerServices.MethodImpl(Runtime.CompilerServices.MethodImplOptions.NoInlining)> _
Get
\'CanReadProperty(True)
Return mId
End Get
End Property
Public Property Name() As String
<System.Runtime.CompilerServices.MethodImpl(Runtime.CompilerServices.MethodImplOptions.NoInlining)> _
Get
\'CanReadProperty(True)
Return mName
End Get
<System.Runtime.CompilerServices.MethodImpl(Runtime.CompilerServices.MethodImplOptions.NoInlining)> _
Set(ByVal Value As String)
\'CanWriteProperty(True)
If Value Is Nothing Then Value = \"\"
If mName <> Value Then
mName = Value
PropertyHasChanged()
End If
End Set
End Property
Public ReadOnly Property Resources() As ProjectResources
Get
Return mResources
End Get
End Property
End Class
Public Class ProjectDTO
Private _id As Guid
Public Property Id() As Guid
Get
Return _id
End Get
Set(ByVal value As Guid)
_id = value
End Set
End Property
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Private _resources As New List(Of ProjectResourceDTO)()
Public Property MyResources() As List(Of ProjectResourceDTO)
Get
Return _resources
End Get
Set(ByVal value As List(Of ProjectResourceDTO))
_resources = value
End Set
End Property
End Class
Mapper.CreateMap(Of ProjectDTO, Project)().ConstructUsing(Function(src As ProjectDTO) Project.NewProject())
Mapper.CreateMap(Of ProjectResourceDTO, ProjectResource)()
Mapper.CreateMap(Of ResourceDTO, Resource)()
我遇到的问题与Resources只读属性的映射有关,该属性是从BusinessListBase继承的集合。将项目添加到此集合的唯一方法是执行方法Assign(resourceId)。
是否有人对如何将DTO对象映射回CSLA对象有任何想法。即我应该如何配置映射器?请注意,在这种特殊情况下,为Resources成员使用解析器无济于事。
谢谢!
禅
没有找到相关结果
已邀请:
1 个回复
磋判粗惊
的同时,您应调用
填充每个属性。