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