Exclude Property from Automapping?

1,479 views
Skip to first unread message

Chris Cyvas

unread,
Dec 18, 2009, 2:30:22 PM12/18/09
to Fluent NHibernate
Is there a way to exclude certain properties from being mapped when
using the AutoMapping functionality? For instance, I have Price and
Quantity in my partial class, but I wanted to be able to add another
partial class that has an ExtendedPrice (Price * Quantity) property in
it that will not be persisted - so I want to exclude that from the
mapping. Any help is appreciated.

James Gregory

unread,
Dec 18, 2009, 7:40:25 PM12/18/09
to fluent-n...@googlegroups.com
http://wiki.fluentnhibernate.org/Auto_mapping#Ignoring_properties

> --
>
> You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
> To post to this group, send email to fluent-n...@googlegroups.com.
> To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.
>
>
>

Chris Cyvas

unread,
Dec 19, 2009, 9:03:57 AM12/19/09
to Fluent NHibernate
You ROCK!

:D

Chris

Farina

unread,
Dec 19, 2009, 11:24:14 AM12/19/09
to Fluent NHibernate
Hi Chris, I faced the same problem and I noticed I would always have
to write the IgnoreProperty using the OverrideAll for each property I
would like to ignore.
So, I created a class inheriting from Attribute like this:

public class NotPersisted : Attribute
{
}

And put the attibute over the non persisted Property:

public class Product
{
[NotPersisted]
public virtual double PriceQuery {get; set;}
}

Now, to ignore all properties in your code which receive the Attribute
NotPersisted:

model.OverrideAll(p =>
{
p.IgnoreProperties(x =>
x.GetCustomAttributes(typeof(IgnoreProperty), false).Length > 0);
});

I am new using the Fluent Auto Map, but it really works for me! :-)

Cheers,
André

Chris Cyvas

unread,
Dec 19, 2009, 11:42:10 AM12/19/09
to Fluent NHibernate
Hi Andre,

Thanks for this! I noticed that in the documentation and figured I'd
have to go that route, but having a solid example will be a big help -
Thanks!

Chris

Reply all
Reply to author
Forward
0 new messages