我有一个BLL类,它包含Country表(CountryCode,CountryName等)中字段的属性。它还有一个属性ioDAL,它是一个DAL类(用SubSonic 2.2创建的)的引用,它具有相同的命名字段。使用AutoMapper的问题将DAL属性映射到BLL属性
我有一个LoadRecord()方法调用DAL的FetchById()方法,通过调用数据库来填充DAL属性(SQL Server 2005 FWIW)。
然后我想要做的,而不是编写代码来填充其DAL等效每个BLL属性,是使用AutoMapper(从CodePlex)。我觉得行应该像
Mapper.CreateMap(ioDAL, Me)()
但是这给错误“型(DAL类/命名空间的命名)的值不能转换为‘的System.Type’”和“类型的值(BLL类/命名空间命名)不能转换为'System.Type'“。
有人请给我一个指导,这个电话应该是什么? (VB.NET VS2005)
EDIT 13-JAN-10 - 吉米问我要表现出更多的代码:
Imports System
Imports System.ComponentModel
Imports AutoMapper
Public Class Country_POCO_Business
' Define property as reference to the relevant DAL class
Public Property ioDAL() As DAL_VB.Test.Country
' rest of property definition here...
End Property
Public Property CountryPk() As String
' rest of property definition here...
End Property
' and so on for other field properties...
Function LoadRecord(ByVal tcPK As String) As Boolean
ioDAL = DAL_VB.Test.Country.FetchByID(tcPK)
If ioDAL.CountryPk = tcPK Then
' set the values for the B/O properties from the DAL equivalents
' THIS IS WHERE THE ERROR OCCURS...
Mapper.CreateMap(ioDAL, Me)()
Return True
Else
Return False
End If
End Function
End Class
对不起,延迟回复 - 只能刚刚回到这个位置。 恐怕从源代码控制的最新版本仍然会给出相同的错误。 我不确定我是否按照您的其他建议。这个应用程序分成多个层,所涉及的代码位于BLL(类库)中。这显然可以从多个应用程序中调用,所以我不确定在哪里放置超载建议。 – kevinw 2009-11-02 13:31:24
你介意发表一小段代码来证明这个问题,所以我可以在我身边重现它吗?另外,堆栈跟踪也可以帮助我。谢谢! – 2009-11-03 13:44:32
@Jimmy--非常抱歉在回复中延迟,同时在别处任务。我现在编辑了我的原始问题,以提供课程大纲; VS2005在Mapper.CreateMap(ioDAL,Me)中给出了错误“类型DAL_VB.Test的值不能转换为'System.Type'”,并且“类型BLL.Country_POCO_Business的值不能转换为'System.Type'”( )线。 – kevinw 2010-01-13 17:40:20