I have spent two full days trying to find out how to add auditing fields to 
my solution which  uses Fluent NHibernate with auto-mapping.  I would like 
the audit times to be generated by the database to maintain a consistent 
timestamp even if multiple computers have time set incorrectly.  I see that 
ClasslikeMapBase has a SQLInsert function but I cannot find any 
documentation explaining how to use this nor a convention that provides 
such functionality.   Below is my CreateSessionFactory code:

 

 

private ISessionFactory CreateSessionFactory()

             {

            //The following configuration retrieves values specified in the 
App.Config

            var nCFG = new NHibernate.Cfg.Configuration();

            nCFG.Configure();

            return Fluently.Configure(nCFG)

            

            //Auto mapping           

            .Mappings

            (

                val => val.AutoMappings.Add

                (

                    //This will include any classes in the same assembly as 
leServiceProvider with the LincolnElectric.PowerWaveServer.Database 
namespace

                    AutoMap.AssemblyOf<leServiceProvider>()    

                        .Where(t => t.Namespace == 
"LincolnElectric.PowerWaveServer.Database")       

                        .Conventions.AddFromAssemblyOf<XmlTypeConvention>()

                        .Conventions.AddFromAssemblyOf<IPAddressConvention
>()

                        .Conventions.AddFromAssemblyOf<
ServiceProviderHasManyConvention>()

                        .Conventions.Add(new DefaultAutiableConvention())

                        .Conventions.Add<DefaultTableConvention>()

                    )

                    

            )

 

            .ExposeConfiguration

            (

                cfg =>

                {

                    //Enable updating/creating tables

                    var schemaUpdate = new SchemaUpdate(cfg);

                    schemaUpdate.Execute(false, true);

                    string schemaExceptions = string.Empty;

                    foreach (var ex in schemaUpdate.Exceptions)

                    {

                        System.Console.WriteLine(ex.Message);

                        schemaExceptions +=  ex.Message + Environment.NewLine 
;

                    }

                    if (schemaExceptions != string.Empty)

                        throw new ArgumentException("NHibernate 
configuration error: " + schemaExceptions);

 

                    

                    //Add listeners to update Updated & Created Audit 
columns

                    //cfg.AppendListeners(ListenerType.PreUpdate, new 
IPreUpdateEventListener[] { new NHListener() });

                    //cfg.AppendListeners(ListenerType.PreInsert, new 
IPreInsertEventListener[] { new NHListener() });

                }

            )

            .BuildSessionFactory();

             }

 

If anyone can provide an answer or a link to a solution, I would greatly 
appreciate it.

 

Second question:  I came across a link that stated there is a bug when 
using dynamic updating and cfg.AppendListeners(ListenerType.PreUpdate, new 
IPreUpdateEventListener[] { new NHListener() }).  Is this an open issue?

 

Thank you so much for your time,

kar
Show trimmed content 

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fluent-nhibernate+unsubscr...@googlegroups.com.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
Visit this group at http://groups.google.com/group/fluent-nhibernate.
For more options, visit https://groups.google.com/d/optout.

Reply via email to