views:

470

answers:

1

I have a BLL class which contains properties for the fields in a Country table (CountryCode, CountryName, etc). It also has a property ioDAL, which is a reference to a DAL class (created with SubSonic 2.2), which has same named fields.

I have a LoadRecord() method which calls the DAL's FetchById() method that populates the DAL properties by calling the database (SQL Server 2005 FWIW).

What I then want to do, rather than writing code to populate each BLL property from its DAL equivalent, is to use AutoMapper (from CodePlex). I think the line should be something like

Mapper.CreateMap(ioDAL, Me)()

but this gives errors "Value of type (DAL class / namespace naming) cannot be converted to 'System.Type'" and "Value of type (BLL class / namespace naming) cannot be converted to 'System.Type'".

Can somebody please give me a guide as to what this call should be? (VB.NET VS2005)


EDIT 13-Jan-10 - Jimmy asked me to show some more code:

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
A: 

First things first, you might consider using the CreateMap(Of DalType, Of BllType)() overload instead. Unless you don't know types at compile time (as is the case with anonymous types), it's better to configure your type maps just once per application lifetime, in Main() or Application_Start or whatever.

Second, I fixed an issue where AutoMapper tries to validate the dynamic mapping, but I took that off. Try pulling down the latest version from source control (http://code.google.com/p/automapperhome/) and see if that works for you now.

Jimmy Bogard
Sorry for the delay in replying - have only just been able to get back to this.I'm afraid that the latest build from the source control still gives the same error.I'm not sure that I follow your other suggestion. This application is split into multiple layers, the code in question is in the BLL (class library). This can obviously be called from multiple applications, so I'm not sure where to put your overload suggestion.
kevinw
Would you mind posting a small snippet of code that demonstrated the problem, so I could reproduce it on my side? Also, a stack trace would also really help me out. Thanks!
Jimmy Bogard
@Jimmy - very sorry for delay in replying, have been tasked elsewhere in the meantime. I have now edited my original question to give an outline of the class; VS2005 gives the errors "Value of type DAL_VB.Test cannot be converted to 'System.Type'" and "Value of type BLL.Country_POCO_Business cannot be converted to 'System.Type'" at the Mapper.CreateMap(ioDAL, Me)() line.
kevinw