0

我有一个 BLL 类,其中包含 Country 表中字段的属性(CountryCode、CountryName 等)。它还有一个属性 ioDAL,它是对 DAL 类(使用 SubSonic 2.2 创建)的引用,该类具有相同的命名字段。

我有一个 LoadRecord() 方法,它调用 DAL 的 FetchById() 方法,该方法通过调用数据库(SQL Server 2005 FWIW)填充 DAL 属性。

然后我想要做的是使用 AutoMapper(来自 CodePlex),而不是编写代码来从其 DAL 等效项中填充每个 BLL 属性。我认为这条线应该是

Mapper.CreateMap(ioDAL, Me)()

但这会产生错误“类型的值(DAL 类/命名空间命名)不能转换为'System.Type'”和“类型的值(BLL 类/命名空间命名)不能转换为'System.Type'”。

有人可以给我一个关于这个电话应该是什么的指南吗?(VB.NET VS2005)


EDIT 13-Jan-10 - Jimmy 让我展示更多代码:

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
4

1 回答 1

1

首先,您可以考虑改用 CreateMap(Of DalType, Of BllType)() 重载。除非您在编译时不知道类型(就像匿名类型的情况一样),否则最好在每个应用程序生命周期中只配置一次类型映射,在 Main() 或 Application_Start 或其他任何地方。

其次,我修复了 AutoMapper 尝试验证动态映射的问题,但我取消了它。尝试从源代码管理 ( http://code.google.com/p/automapperhome/ )中提取最新版本,看看现在是否适合您。

于 2009-10-16T12:58:26.903 回答