Glad to help. It seems not to have solved my problem though. A mapping file for DomainObject is still being generated. I think because ForTypesThatDeriveFrom<DomainObject> (or IMappingOverride.Override) creates an AutoMap<DomainObject> for DomainObject (which is meant to be used just for merging with AutoMaps of derived types since DomainObject is a base class) it still bypasses the logic that would exclude it. This means that base classes make it into the final mapping regardless of their exclusion by Conventions.IsBaseClass. I think we might need to do a final filter after all the merges have been done to exclude base class AutoMaps that were created by ForTypesThatDeriveFrom or via an IMappingOverride. Alternatively we could add a parameter to AutoMapper.MergeMap called isBaseClass (bool) which we could use to determine if mapEverythingInClass() should be called (i.e do we just want to merge with mappings for derived types or do we want to map the class itself as well).
On Feb 17, 10:59 pm, James Gregory <[email protected]> wrote: > Thanks for the patch, I will review it tomorrow. > > On Tue, Feb 17, 2009 at 6:58 PM, Jimit <[email protected]> wrote: > > > I've created a patch adding support for mapping entities in multiple > > assemblies. It basically follows the logic I suggested in the posts > > above. I've added a test verifying it works and as well as updated 3 > > tests that were failing as a result (I think) of a recent change in > > the mappings pushing column declarations in the xml from attributes to > > elements. I just updated the XPATH query to point to the "column" > > element and set the HasAttribute to look for the "name" attribute for > > all three tests. They are (in the AutoPersistenceModelTests class): > > MapsPropertyWithPropertyConvention, > > ComponentColumnConventionReceivesProperty and > > ComponentPropertiesAssumeComponentColumnPrefix. You might want to > > confirm that that is the expected behaviour. > > > In order to create the test for mapping entities from multiple > > assemblies I added a reference to Examples.FirstProject to the test > > project. > > > Here's the patch. I apologize in advance if this isn't the accepted > > way to submit patches. Just let me know how it's normally done and > > I'll do so henceforth.: > > > Index: src/FluentNHibernate.Testing/AutoMap/ > > AutoPersistenceModelTests.cs > > =================================================================== > > --- src/FluentNHibernate.Testing/AutoMap/AutoPersistenceModelTests.cs > > (revision 0) > > +++ src/FluentNHibernate.Testing/AutoMap/AutoPersistenceModelTests.cs > > (revision 0) > > @@ -0,0 +1,477 @@ > > +using System; > > +using System.Diagnostics; > > +using FluentNHibernate.AutoMap; > > +using FluentNHibernate.AutoMap.TestFixtures.ComponentTypes; > > +using FluentNHibernate.AutoMap.TestFixtures.CustomTypes; > > +using NUnit.Framework; > > +using SuperTypes = FluentNHibernate.AutoMap.TestFixtures.SuperTypes; > > +using FluentNHibernate.AutoMap.TestFixtures; > > + > > +namespace FluentNHibernate.Testing.AutoMap > > +{ > > + using Examples.FirstProject.Entities; > > + using Fixtures.EntitiesInMultipleAssemblies; > > + > > + [TestFixture] > > + public class AutoPersistenceModelTests : BaseAutoPersistenceTests > > + { > > + [Test] > > + public void MapsPropertyWithPropertyConvention() > > + { > > + var autoMapper = AutoPersistenceModel > > + .MapEntitiesFromAssemblyOf<ExampleCustomColumn>() > > + .Where(t => t.Namespace == > > "FluentNHibernate.AutoMap.TestFixtures") > > + .WithConvention(convention => > > + { > > + convention.AddPropertyConvention(new > > XXAppenderPropertyConvention()); > > + }); > > + > > + autoMapper.Configure(cfg); > > + > > + new AutoMappingTester<ExampleClass>(autoMapper) > > + .Element("class/proper...@name='LineOne']/ > > column").HasAttribute("name", "LineOneXX"); > > + } > > + > > + [Test] > > + public void TestAutoMapsIds() > > + { > > + var autoMapper = AutoPersistenceModel > > + .MapEntitiesFromAssemblyOf<ExampleCustomColumn>() > > + .Where(t => t.Namespace == > > "FluentNHibernate.AutoMap.TestFixtures"); > > + > > + autoMapper.Configure(cfg); > > + > > + new AutoMappingTester<ExampleClass>(autoMapper) > > + .Element("class/id").Exists(); > > + } > > + > > + [Test] > > + public void TestAutoMapsProperties() > > + { > > + var autoMapper = AutoPersistenceModel > > + .MapEntitiesFromAssemblyOf<ExampleClass>() > > + .Where(t => t.Namespace == > > "FluentNHibernate.AutoMap.TestFixtures"); > > + > > + autoMapper.Configure(cfg); > > + > > + new AutoMappingTester<ExampleClass>(autoMapper) > > + .Element("//property").HasAttribute("name", > > "ExampleClassId"); > > + } > > + > > + [Test] > > + public void TestAutoMapIgnoresProperties() > > + { > > + var autoMapper = AutoPersistenceModel > > + .MapEntitiesFromAssemblyOf<ExampleClass>() > > + .Where(t => t.Namespace == > > "FluentNHibernate.AutoMap.TestFixtures") > > + .ForTypesThatDeriveFrom<ExampleCustomColumn>(c => > > c.IgnoreProperty(p => p.ExampleCustomColumnId)); > > + > > + autoMapper.Configure(cfg); > > + > > + new AutoMappingTester<ExampleCustomColumn>(autoMapper) > > + .Element("//property").DoesntExist(); > > + } > > + > > + [Test] > > + public void TestAutoMapManyToOne() > > + { > > + var autoMapper = AutoPersistenceModel > > + .MapEntitiesFromAssemblyOf<ExampleClass>() > > + .Where(t => t.Namespace == > > "FluentNHibernate.AutoMap.TestFixtures"); > > + > > + autoMapper.Configure(cfg); > > + > > + new AutoMappingTester<ExampleClass>(autoMapper) > > + .Element("//many-to-one").HasAttribute("name", > > "Parent"); > > + } > > + > > + [Test] > > + public void TestAutoMapOneToMany() > > + { > > + var autoMapper = AutoPersistenceModel > > + .MapEntitiesFromAssemblyOf<ExampleParentClass>() > > + .Where(t => t.Namespace == > > "FluentNHibernate.AutoMap.TestFixtures"); > > + > > + autoMapper.Configure(cfg); > > + > > + new AutoMappingTester<ExampleParentClass>(autoMapper) > > + .Element("//bag") > > + .HasAttribute("name", "Examples"); > > + } > > + > > + [Test] > > + public void TestAutoMapPropertyMergeOverridesId() > > + { > > + var autoMapper = AutoPersistenceModel > > + .MapEntitiesFromAssemblyOf<ExampleClass>() > > + .Where(t => t.Namespace == > > "FluentNHibernate.AutoMap.TestFixtures") > > + .ForTypesThatDeriveFrom<ExampleClass>(map => map.Id(c > > => c.Id, "Column")); > > + > > + autoMapper.Configure(cfg); > > + > > + new AutoMappingTester<ExampleClass>(autoMapper) > > + .Element("class/id") > > + .HasAttribute("name", "Id") > > + .HasAttribute("column", "Column"); > > + } > > + > > + [Test] > > + public void TestAutoMapPropertySetPrimaryKeyConvention() > > + { > > + var autoMapper = AutoPersistenceModel > > + .MapEntitiesFromAssemblyOf<ExampleClass>() > > + .Where(t => t.Namespace == > > "FluentNHibernate.AutoMap.TestFixtures") > > + .WithConvention(c=> c.GetPrimaryKeyName = p=> p.Name > > + "Id"); > > + > > + autoMapper.Configure(cfg); > > + > > + new AutoMappingTester<ExampleClass>(autoMapper) > > + .Element("class/id") > > + .HasAttribute("name", "Id") > > + .HasAttribute("column", "IdId"); > > + } > > + > > + [Test] > > + public void TestAutoMapIdUsesConvention() > > + { > > + var autoMapper = AutoPersistenceModel > > + .MapEntitiesFromAssemblyOf<PrivateIdSetterClass>() > > + .Where(t => t.Namespace == > > "FluentNHibernate.AutoMap.TestFixtures") > > + .WithConvention(convention => > > + convention.IdConvention = id => > > id.Access.AsLowerCaseField()); > > + > > + autoMapper.Configure(cfg); > > + > > + new AutoMappingTester<PrivateIdSetterClass>(autoMapper) > > + .Element("class/id") > > + .HasAttribute("access", "field.lowercase"); > > + } > > + > > + [Test] > > + public void TestAutoMapPropertySetManyToOneKeyConvention() > > + { > > + var autoMapper = AutoPersistenceModel > > + .MapEntitiesFromAssemblyOf<ExampleClass>() > > + .Where(t => t.Namespace == > > "FluentNHibernate.AutoMap.TestFixtures") > > + .WithConvention(c => > > + { > > + c.GetForeignKeyName = p => > > p.Name + "Id"; > > + }); > > + > > + autoMapper.Configure(cfg); > > + > > + new AutoMappingTester<ExampleClass>(autoMapper) > > + .Element("//many-to-one") > > + .HasAttribute("name", "Parent") > > + .HasAttribute("column", "ParentId"); > > + } > > + > > + [Test] > > + public void TestAutoMapPropertySetOneToManyKeyConvention() > > + { > > + var autoMapper = AutoPersistenceModel > > + .MapEntitiesFromAssemblyOf<ExampleClass>() > > + .Where(t => t.Namespace == > > "FluentNHibernate.AutoMap.TestFixtures") > > + .WithConvention(c => c.GetForeignKeyNameOfParent = t > > => t.Name + "Id"); > > + > > + autoMapper.Configure(cfg); > > + > > + new AutoMappingTester<ExampleParentClass>(autoMapper) > > + .Element("//bag") > > + .HasAttribute("name", "Examples") > > + .Element("//key") > > + .HasAttribute("column", "ExampleParentClassId"); > > + } > > + > > + [Test] > > + public void TestAutoMapPropertySetFindPrimaryKeyConvention() > > + { > > + var autoMapper = AutoPersistenceModel > > + .MapEntitiesFromAssemblyOf<ExampleClass>() > > + .Where(t => t == typeof(ExampleClass)) > > + .WithConvention(c => c.FindIdentity = p => p.Name == > > p.DeclaringType.Name + "Id" ); > > + > > + autoMapper.Configure(cfg); > > + > > + new AutoMappingTester<ExampleClass>(autoMapper) > > + .Element("class/id") > > + .HasAttribute("name", "ExampleClassId") > > + .HasAttribute("column", "ExampleClassId"); > > + } > > + > > + [Test] > > + [ExpectedException(typeof(NullReferenceException))] > > + > > ... > > read more » --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en -~----------~----~----~----~------~----~------~--~---
