Country テーブル (CountryCode、CountryName など) のフィールドのプロパティを含む BLL クラスがあります。また、同じ名前のフィールドを持つ DAL クラス (SubSonic 2.2 で作成) への参照であるプロパティ ioDAL もあります。
データベース (SQL Server 2005 FWIW) を呼び出して DAL プロパティを設定する DAL の FetchById() メソッドを呼び出す LoadRecord() メソッドがあります。
次に、対応する DAL から各 BLL プロパティを設定するコードを記述するのではなく、AutoMapper (CodePlex から) を使用します。行は次のようなものにする必要があると思います
Mapper.CreateMap(ioDAL, Me)()
しかし、これにより、「型の値 (DAL クラス/名前空間の命名) を 'System.Type' に変換できません」および「型の値 (BLL クラス/名前空間の命名) を 'System.Type' に変換できません」というエラーが発生します。
この呼び出しがどうあるべきかについて、誰かが私にガイドを教えてもらえますか? (VB.NET VS2005)
2010 年 1 月 13 日編集 - 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