nhibernate - Adding IAutoMappingOverride with interface for all domain classes -


i have iauditable interface defines class domain auditable.

public interface iauditable {     datetime createat { get; }     iuser createby { get; }     datetime? updateat { get; }     iuser updateby { get; } } 

for these classes (there many) implement interface, configuration same! decided override convention:

public class audityconvention : iautomappingoverride<iauditable> {     public void override(automapping<iauditable> mapping)     {         mapping.map(p => p.createat).readonly().access.property().not.nullable().not.update().default("getdate()").generated.insert();         mapping.references<usuario>(p => p.createby).not.nullable().not.update();          mapping.map(p => p.updateat).readonly().access.property().default("getdate()").not.insert().generated.always();         mapping.references<usuario>(p => p.updateby).nullable().not.insert();     } } 

and configure it

    _configuration = fluently.configure() // config app.config         .mappings(m =>         {             m.automappings.add(                 automap.assemblyof<usuario>()                 .useoverridesfromassemblyof<audityconvention>()                 .conventions.setup(c => c.addfromassemblyof<enumconvention>())             );              m.fluentmappings                 .addfromassemblyof<usuariomap>()                 .conventions.addfromassemblyof<enumconvention>()                                     ;         })         .buildconfiguration();  sessionfactory = _configuration.buildsessionfactory();  session = sessionfactory.opensession();  var export = new schemaexport(_configuration); export.drop(false, true); // drop , recreate database (just make sure settings being applied) export.execute(false, true, false); // create de database  

with app.config

    <appsettings>     <add key="fluentassertions.testframework" value="mstest"/> </appsettings>     <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">     <session-factory>         <property name="connection.provider">nhibernate.connection.driverconnectionprovider</property>         <property name="dialect">nhibernate.dialect.mssql2008dialect</property>         <property name="connection.connection_string_name">data</property>         <property name="show_sql">true</property>     </session-factory> </hibernate-configuration> 

exemple domain class:

public class entidade : iauditable {     public virtual int id { get; protected set; }     [stringlength(255)]     public virtual string nome { get; set; }      // implements iauditable     public virtual datetime createat { get; protected set; }     public virtual iuser createby { get; set; }     public virtual datetime? updateat { get; protected set; }     public virtual iuser updateby { get; set; } } 

and map it:

public class entidademap : classmap<entidade> {     public entidademap()     {         id(p => p.id);         map(p => p.nome);          table("entidades");     } } 

results:

enter image description here

question

what doing wrong? how create convention classes implement iauditable settings same!

the part of configuration below added later. read, overwrite support automappings conventions.

m.automappings.add(     automap.assemblyof<usuario>()     .useoverridesfromassemblyof<audityconvention>()     .conventions.setup(c => c.addfromassemblyof<enumconvention>()) ); 

i think you're out of luck. don't believe overrides work on interfaces. you're better off doing this:

public class baseauditable : iauditable {    .... }  public class entidade : baseauditable { ... } 

you can use

  iautomappingoverride<baseauditable> instead of iautomappingoverride<iauditable> 

i hope i'm wrong tried make work many times interfaces no luck.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -