Ignoring properties on manually mapped entities

6 views
Skip to first unread message

Joseph LeBlanc

unread,
Nov 5, 2009, 4:12:33 PM11/5/09
to Fluent NHibernate
I'm using both the auto-mapper as well as manually mapping entities in
my current project. This is because I'm dealing with a legacy database
where a significant amount of the existing tables and relationships
simply require manual intervention to map properly.

However I need to be able to mark certain properties that should be
ignored when generating mappings on types that are auto-mapped or
manually mapped.I have created a custom attribute that I use with
OverrideAll() in the auto-mapper and this works fine for auto-mapped
entities but I'm having trouble figuring out what the equivalent would
be when manually mapping types.

Here's my mapping code:

this.sessionFactory = Fluently.Configure()
.Database
(FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2005.ConnectionString
(c => c
.Is(this.dbSettings.ConnectionString)))
.Mappings(m =>
{
m.AutoMappings.Add(
AutoMap.AssemblyOf<NHibernateAutoMapBase>()
.Setup(s =>
{
s.IsBaseType = type => type == typeof
(NHibernateAutoMapBase);
})
.Where(d => (d.BaseType != null &&
d.BaseType.Equals(typeof(NHibernateAutoMapBase))))
.OverrideAll(map =>
{
map.IgnoreProperties(x =>
x.GetCustomAttributes(typeof(NHibernateIgnorePropertyAttribute),
true).Count() > 0);
})
.Conventions.AddFromAssemblyOf<NHibernateAutoMapBase>
()
);

//m.AutoMappings.ExportTo("Auto");

Assembly a = Assembly.GetAssembly(typeof
(NHibernateAutoMapBase));
foreach (Type t in a.GetTypes())
{
if (t.GetInterface(typeof
(IMappingProvider).FullName) != null)
{
m.FluentMappings.Add
(t);
}
}

m.FluentMappings.Conventions.AddFromAssemblyOf<NHibernateAutoMapBase>
();
//m.FluentMappings.ExportTo("Manual");
})
.BuildSessionFactory();

Paul Batum

unread,
Nov 6, 2009, 6:32:57 PM11/6/09
to fluent-n...@googlegroups.com
Hi Joseph,

I'm a little confused. Why do you need to detect the attribute for your manual mappings? By their very definition, they only map what you specify.

Sorry if I'm missing something obvious.

Paul Batum

Joseph LeBlanc

unread,
Nov 9, 2009, 11:33:22 AM11/9/09
to Fluent NHibernate
I was getting a fluent-nhibernate configuration error but it looks
like it was just because I hadn't marked my property virtual.

Doh.

On Nov 6, 3:32 pm, Paul Batum <paul.ba...@gmail.com> wrote:
> Hi Joseph,
>
> I'm a little confused. Why do you need to detect the attribute for your
> manual mappings? By their very definition, they only map what you specify.
>
> Sorry if I'm missing something obvious.
>
> Paul Batum
>
> On Fri, Nov 6, 2009 at 8:12 AM, Joseph LeBlanc
> <joseph.s.lebl...@gmail.com>wrote:
> >                .BuildSessionFactory();- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages