Fluent NHibernate: Mixing Automapping and manual mapping
Asked Answered
B

1

7

If using Fluent NHibernate, is it possible to automap most classes, but specify that a couple of particular classes should be mapped using the regular fluent API rather than being automapped? And if so, can anyone point me to some sample code that shows how to do it?

Thanks!

Bran answered 20/8, 2010 at 10:52 Comment(0)
U
11

It is possible and easy to mix-up mapping configurations:

var cfg = Fluently.Configure()
    .Database(configurer)
    .Mappings(map =>
                  {
                      // Automapping
                      map.AutoMappings.Add(AutoMap.Assemblies(Assembly.GetExecutingAssembly())
                                             .Where(type => type == typeof(Domain.Market.Share))
                                             .Where(type => type == typeof(Domain.HR.Employee)));

                      // Fluent mappings
                      map.FluentMappings.AddFromAssemblyOf<Domain.Client.Macys>();
                  });

Good luck. ;-)

Umbra answered 20/8, 2010 at 12:47 Comment(1)
Thanks Rafael, that does look easy!Bran

© 2022 - 2024 — McMap. All rights reserved.