cam i map a shared interface to remove duplicated mapping?

17 views
Skip to first unread message

livioc

unread,
Jan 9, 2017, 9:52:30 AM1/9/17
to Fluent NHibernate
hi, i'm using the fluentmapping (i.e. no automappings), i have some interfaces implemented by different entities types,
can i map these interfaces (or use a convention) to remove the duplicated mapping code of the fields defined by each interface?

for example i have this interfaces
interface IName {
    string Name {get;set;}
}

interface IDescription {
       string Description {get;set;
}

and this type
class TypeA : IName, IDescription {
  //IName Impl
  //IDescription Impl
  int Value;
}

what i like is to use something as
class NameMap : ClassMap<IName> {
   //map property Name
}
class DescriptionMap : ClassMap<IDescription> {
   //map property Description
}
class TypeAMap : ClassMap<TypeA> {
   //explicitly map  only the property Value using NameMap/DescriptionMap
}

is it possible?
thanks

mwpowellhtx

unread,
Jan 10, 2017, 5:25:50 AM1/10/17
to Fluent NHibernate
Off hand I do not think it's possible, even with the subclass mapping. Consider why due to single inheritance types, versus multiple implemented interfaces.

This is because what you end up with are actually proxy instances managed by the session.

When I have something like that I consider a base class, with subclass mapping, or simple class map inheritance, or possibly even component map.

After awhile, though, I feel your pain, especially for those cross cutting concerns.

HTH

Regards,

Michael

Reply all
Reply to author
Forward
0 new messages