Is it possible to Automap from multiple assemblies?

Tom Bushell's Avatar

Tom Bushell

19 Feb, 2010 05:11 PM via web

Is it possible to Automap from multiple assemblies?

I found some postings that indicate

AutoPersistanceModel.AddEntityAssembly()

might let me do this, but have been unable to make it work.

If this is possible, can anyone supply a code fragment that shows how to automap from multiple assemblies, or point me to an example that works?

Thanks,

-Tom Bushell

  1. Support Staff 2 Posted by James Gregory on 19 Feb, 2010 08:52 PM

    James Gregory's Avatar

    Yeah, that's always been an awkward thing to do; and as usual, as something that I don't personally do, it hasn't been high on the priority list as far as things to fix go.

    I've just committed a fix, and if you're able to update to the latest source you'll be able to take advantage of it.

    AutoMap.Assemblies(assemblyOne, assemblyTwo); // params
    AutoMap.Assemblies(assembliesCollection);
    

    If you're unable to update, your best bet is to automap each assembly individually using AutoMap.AssemblyOf<T>() and adding them to the AutoMappings collection in your configuration.

  2. Support Staff 3 Posted by James Gregory on 04 Mar, 2010 02:07 PM

    James Gregory's Avatar

    Hey Tom, was this of any use?

  3. 4 Posted by Tom Bushell on 04 Mar, 2010 03:02 PM

    Tom Bushell's Avatar

    Hey James,

    Sorry for not getting back to you.

    Just after you made the change, my project took an unexpected turn, and I didn't get a chance to try it.

    I'll try to take a look today, and let you know how I make out.

    Thanks,

    -Tom

    -----Original Message-----
    From: James Gregory
    [mailto:***@tenderapp.com]
    Sent: Thursday, March 04, 2010 9:07 AM
    To: ***@bic.com
    Subject: Re: Is it possible to Automap from multiple assemblies? [Help
    and guidance]

  4. 5 Posted by tbushell on 04 Mar, 2010 07:57 PM

    tbushell's Avatar

    James,

    This seems to work fine. In the following fragment, "TestMap" is a class in another assembly (all the other classes are in the executing assembly).

            return AutoMap.Assemblies(Assembly.GetExecutingAssembly(), Assembly.GetAssembly(typeof(TestMap) ))
                .Where(t => t.Name == "TestMap" ||
                            t.Name == "DlsAppOverlordExportRunData" ||
                            t.Name == "DlsAppOverlordExportData" ||
                            t.Namespace == "BI_OverlordDlsAppCore.C21Cfr" ||
                            t.Name == "MarkHouwinkSakuradaParams" ||
                            t.Name == "DistributionResults" ||
                            t.Name == "ContinDistributionResults" ||
                            t.Name == "NnlsDistributionResults"
                       )
    

    The hardest part (for me) was figuring out how to specify the Assembly parameters, since I'd never worked with that part of System.Reflection before. I'd be interested in your suggestions on better ways to do this.

    -Tom

  5. Support Staff 6 Posted by James Gregory on 05 Mar, 2010 09:47 AM

    James Gregory's Avatar

    There's a few ways to get an Assembly instance, but the easiest one that I've found (as long as the assembly is already referenced by your current project) is to just do: typeof(TestMap).Assembly.

  6. James Gregory closed this discussion on 05 Mar, 2010 09:47 AM.

Comments are currently closed for this discussion. You can start a new one.