我有一个 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