When using automap, how can you exclude some classes?

29 views
Skip to first unread message

5x1llz

unread,
Jun 2, 2009, 2:34:28 AM6/2/09
to Fluent NHibernate
Hello,

I'm pretty new to FNhib, for now I have found a way around this, was
wondering if there was a better way.

I have:

Mydomain.Entities (which is automapped)

I have a composite Entity contains automapped Entities but itself does
not have a table, I'm using it mostly for the shape.

For now I've put this class into another domain as the "Entities"
domain is automapped and FNH throws an error for this one class which
is not mapped to the DB.

Is using an alternate namespace the suggested approach or do I need to
override and keep all Entities (persisted or not) in the same
namespace?

Thanks!



James Gregory

unread,
Jun 2, 2009, 3:53:05 AM6/2/09
to fluent-n...@googlegroups.com
You don't need to have unpersisted entities in the same place as persisted ones (although you can, but your Where clause will be trickier). The separate namespace for unmapped classes is the simplest approach; however, if you're using the class as a base-class for a mapped entity then you may need to let FNH know how to find it.

I'd use the WithSetup method to change how the automapper is configured so it knows that your base-class shouldn't be mapped as an entity.

WithSetup(c => c.IsBaseClass =
  type => type == typeof(MyBaseEntity));

Try that first to see if it makes any difference. If it doesn't, then you probably do need to let the automapper know where MyBaseEntity lives. You could either move it back into the location of your mapped entities or change your Where call to include it.

Something like:

Where(type =>
  type.Namespace == "Mydomain.Entities" || type == typeof(MyBaseEntity));

upgrade...@5x1llz.com

unread,
Jun 2, 2009, 10:27:40 AM6/2/09
to Fluent NHibernate
Thanks for the quick answer...! it's actually a composite object but
it's good to know the options. I'll try this approach, sounds like it
will work in this instance

On Jun 2, 1:53 am, James Gregory <jagregory....@gmail.com> wrote:
> You don't need to have unpersisted entities in the same place as persisted
> ones (although you can, but your Where clause will be trickier). The
> separate namespace for unmapped classes is the simplest approach; however,
> if you're using the class as a base-class for a mapped entity then you may
> need to let FNH know how to find it.
>
> I'd use the WithSetup method to change how the automapper is configured so
> it knows that your base-class shouldn't be mapped as an entity.
>
> WithSetup(c => c.IsBaseClass =
>   type => type == typeof(MyBaseEntity));
>
> Try that first to see if it makes any difference. If it doesn't, then you
> probably do need to let the automapper know where MyBaseEntity lives. You
> could either move it back into the location of your mapped entities or
> change your Where call to include it.
>
> Something like:
>
> Where(type =>
>   type.Namespace == "Mydomain.Entities" || type == typeof(MyBaseEntity));
>
Reply all
Reply to author
Forward
0 new messages