views:

13

answers:

1

Hi!

I'm trying to use fluent nhibernate to auto map most properties of a class, and then manually map 1 or 2 properties of that same class (without having to manually map all the other variables in the class map).

I have a class with a couple of dozen properties, but one of those properties is a string which needs to be a long length.

Here's an example:

Person class has fields: ID, firstname, lastname, description, and a few dozen other fields.

I would auto map the class but I want 'description' to be a long string, not a nvarchar(255).

So I try:

public class PersonMap : ClassMap { public PersonMap() { Map(x => x.description).Length(4000); } }

but this doesn't auto map all the other properties (an exception is thrown). It's expecting declarations for each property.

Is there a way to accomplish what I'm trying to do?

If anyone needs it, here's the code I'm using to declare the configuration:

FluentConfiguration cfg = Fluently.Configure()
.Database(FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2000.ConnectionString(Cn));
        AutoPersistenceModel mdl = 
            AutoMap.Assembly(System.Reflection.Assembly.GetExecutingAssembly());

        cfg.Mappings(m => m.AutoMappings.Add(mdl.Where(type =>
        type.Namespace != null && type.Namespace.ToLower() == strNamespace.ToLower() )));

Thanks!

A: 

Ok I figured it out. There's a method called 'override' that I can use when declaring the configuration, and in there I can specify all the overrides for specific properties:

AutoPersistenceModel mdl = AutoMap.Assembly(System.Reflection.Assembly.GetExecutingAssembly());

mdl.Override(map => { map.Map(x => x.description).Length(4000); });

Rob Smith