Fluent NHibernate automapping class conventions aren't being applied to entire class hierarchy -
i'm trying automap simple inheritance hierarchy fluent nhibernate, , need have different name each table class (underscores instead of pascal case). seems obvious place use conventions. want use table-per-subclass strategy, combination seems causing me issue: convention applied base class of hierarchy.
here's automapping:
automap .assemblyof<baserule>() .includebase<baserule>() // "baserule" abstract class .conventions.add( defaultcascade.all() ) .conventions.add<oracletablenameconvention>() how want classes mapped (class name -> table name):
abstract class baserule -> base_rule class numberrule : baserule -> number_rule class patternstringrule : baserule -> pattern_string_rule what i'm getting:
baserule -> base_rule numberrule -> numberrule patternstringrule -> patternstringrule as can see, base class being changed. here's existing convention, can see how i'm defining it:
public class oracletablenameconvention : iclassconvention { public void apply(iclassinstance instance) { string fixedname = instance.entitytype.name.tounderscorednaming(); instance.table(fixedname); } } i've looked isubclassconvention interface, , can see no way in there adjust name of table (which makes enough sense, subclasses aren't in own table).
if delete includebase line automapping, names become want, except becomes table-per-concrete-class. want use table-per-subclass, leaving common data in 1 shared base table.
i can add overrides each name, , if have to, i'd rather not.
it seems should supported behavior. how can have naming convention apply each table in hierarchy, without going table-per-concrete-class?
as posted question, figured out.
ijoinedsubclassconvention interface needed implement.
public class oraclesubclassconvention : ijoinedsubclassconvention { public void apply(ijoinedsubclassinstance instance) { string fixedname = instance.entitytype.name.tounderscorednaming(); instance.table(fixedname); } } i found looking had method table(string).
Comments
Post a Comment