In Fluent NHibernate, how do you combine automatic types with human types?

Right now, I'm migrating from my project from the classic free-style nhibernate, defining manually ClassMap

for each domain object so that the auto-mapper will automatically generate the mappings for me. But I would like to keep using the classes that I already mapped in classic style until I can tune the automatic changes to match the old classic mappings.

The only problem is that the fluent nhibernate crashes when the autocapter hits a class that has already been rendered in the classic fluent nhibernate style.

Here's my AutoPersistenceModel

setup code:

_autoPersistenceModel = AutoMap.AssemblyOf<DomainEntity>();
_autoPersistenceModel.AddMappingsFromAssembly(typeof (PlayerPersistenceMap).Assembly);

_autoPersistenceModel.Alterations(x =>
                    x.Add<AutoMappingAlteration>())
                .Setup(s =>
                {
                    s.FindIdentity = type => type.Name == "ID";

                    s.IsBaseType = type => (type == typeof(DomainEntity));
                })
                .Conventions
                    .AddFromAssemblyOf<IdentityColumnConvention>()
                    .UseOverridesFromAssemblyOf<PlayerMappingOverride>();

      

Can anyone help me here?

Additional Information:

I also tried the technique mentioned on Wikipedia here . Alas, I still get the error: Duplicate class/entity mapping

.

+2


source to share


1 answer


mixed fluent mappings and auto-join examples on the wiki should work if it's not buggy.

As a job, exclude types that have been manually mapped to you. You would do it with a method Where

as shown in the wiki examples, something like this:

AutoMap.AssemblyOf<DomainEntity>()
  .Where(type => type != typeof(OneOfYourManuallyMappedClasses));

      



If you have a lot of good mappings, you can create a collection to support auto-tuning:

var mappedTypes = new[] { typeof(One), typeof(Two) };

AutoMap.AssemblyOf<DomainEntity>()
  .Where(type => !mappedTypes.Contains(type));

      

Again, this isn't necessary, but if you're sure it doesn't work with the wiki example, I would suggest a problem.

+2


source







All Articles