- if the property has a setter then it's stored in nhibernate and is mapped.
- If it contains a collection then it's mapped as many-to-one
- If the class is inherits from a mapped type then it's a subclass
I dislike the use of extension methods on the NHibernate Configuration.
In my opinion I'd of thought the convention would be about naming conventions and defaults, rather than how you analyse the assmebly - suppose it depends on your definition though.
Anyway I'd just thought I'd start a discussion as to how we define these, as I'm quite keen to look into it.
I agree we need to discuss these ideas, but I'm not interested in knee-jerk reacting to this. We need to get our API implemented properly before we're even able to tackle this, there's no point implementing auto-mapping when we don't even fully support the normal mappings.
new AutoMapIdentity(),
new AutoMapVersion(),
new AutoMapProperty(),
new AutoMapManyToOne(),
new AutoMapOneToMany(),
Jeremy
var autoModel = new AutoPersistenceModel(Assembly.GetAssembly(typeof(AutoMapTests)));
autoModel.AddEntityAssembly(Assembly.GetAssembly(typeof (AutoMapTests)),t => t.Namespace == "FluentNHibernate.AutoMap.Test");
Now that should add the ability to maps load all maps that are manually created, plus automap the other objects. Now here comes the problem I have at the moment, I have no easy way to tell what properties have been manually mapped, so that I can ignore them when automapping. Does anyone know of any easy way to find this out?
Cheers
Andy
var mapping = executeMethod(obj, this, "findMapping", null);
if (mapping != null)
{
  executeMethod(obj, autoMap, "Map", new[] {mapping});
}
else
{
  executeMethod(obj, autoMap, "Map", null);
}
Your right it does smell a tad, here's the problem, I need to execute a generic method either on the base class or on the automapper. However I don't know the type, as it's defined at runtime and this is the only way I could get it to work.
Now if anyone know's a way of calling these generic methods statically typed, I'll send them a big virtual hug as this has break me on refactoring written all over it.
Cheers
Andy
var persistenceModel = new AutoPersistenceModel(Assembly.GetAssembly(typeof(PlotMap)));
persistenceModel.AddEntityAssembly(Assembly.GetAssembly(typeof (Address)), t => (t.Namespace == "Mdis.Entities" && ( t.BaseType == typeof(object))));
persistenceModel.Configure(cfg);
public class PlotMap : AutoMap<Plot>What happens is, first it loads in your automap's then in maps in extra unmapped properties and entities(hope that makes sense). So you only need to specify exceptions to the rule everything else will be mapped straight out the box as if by magic. Now my next challenge will be making this a bit more fluent and specifying conventions across the board as of Chad's suggestion below:
{
  public PlotMap()
  {
     HasManyToMany<Service>(p => p.Services);
  }
}
 var model = AutoPersistenceModel
      .MapEntitiesFromAssemblyOf<AutoMapTests>()
      .Where(t => t.Namespace == "FluentNHibernate.AutoMap.Test")
      .ForTypesThatDeriveFrom<DomainEntity>(map =>
                                                {
                                                    map.UseIdentityForKey(e => e.Id, "Id");
                                                });
I did a spike and got my head around it. Basically, you have a bunch of generic methods and then you’re treating them non-generically.
Â
Will this be called directly by people, or is this mostly internal API stuff?
Â
I was able to create an IAutoMap rather than have AutoMap<T>, IAutoPartMapper instead of the various part mappers (IAutoMapper was confusing because there’s an AutoMapper<T>, but it wasn’t an IAutoMapper, IAutoMapper is really something like IAutoPartMapper, etc).
Â
Anyhow, if you use interfaces for these things and make them non-generic (i.e. don’t make it Foo<T>, just make methods like Foo(Type theType)).
Â
Make the people-facing fluent interfaces generic <T>, but all the internal stuff non-generic otherwise your life will be very painful (as you’ve already found out).
Â
I don’t want to commit my spike code because it’s not tested and it’s sloppy, but maybe we can pair on this sometime if you want, or if you want to research this yourself, etc.
Â
-c
Â
From:
fluent-n...@googlegroups.com [mailto:fluent-n...@googlegroups.com] On
Behalf Of Andrew Stewart
Sent: Friday, August 15, 2008 7:51 AM
To: fluent-n...@googlegroups.com
Subject: [fluent-nhib] Re: Ayende on Fluent nHibernate - AutoMap
Â
Hello
Will this be called directly by people, or is this mostly internal API stuff?