I've been beating my head on a wall for the last few days as to why I get this odd behavior
I have tried the 2 following setups
return _sessionFactory ??
(_sessionFactory = Fluently.Configure()
.Database(MySQLConfiguration.Standard.ConnectionString(cs =>cs.Server("127.0.0.1").Database("azeroth").Username("root").Password("password")))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Database>())
.BuildSessionFactory()
);
return _sessionFactory ??
(_sessionFactory = Fluently.Configure()
.Database(MySQLConfiguration.Standard.ConnectionString(cs => cs.Server("127.0.0.1").Database("azeroth").Username("root").Password("password")))
.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Database>().Where(t => t.Namespace.StartsWith("Azeroth.Database.Auth"))))
.BuildSessionFactory()
);
I have verified that my classes used for the database have a namespace that starts with Azeroth.Database.Auth
If I use #1 everything works pefectly I can query/add/delete/update the database.
If I use #2 I get an exception - unable to execute query - on EVERY database operation.
Hoping someone can shed some light as to why the automapping line doesn't work but the mapping line works.
This is the output of the exception:
NHibernate.Exceptions.GenericADOException: could not execute query at MySql.Data.MySqlClient.MySqlStream.ReadPacket() at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId) at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) at MySql.Data.MySqlClient.MySqlDataReader.NextResult() at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) at MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session) at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) --- End of inner exception stack trace ---
[ SELECT this_.Id as Id0_0_, this_.Username as Username0_0_, this_.Sha_Pass_hash as Sha3_0_0_, this_.Email as Email0_0_, this_.Joindate as Joindate0_0_, this_.LaspIp as LaspIp0_0_, this_.FailedLogins as FailedLo7_0_0_, this_.Locked as Locked0_0_, this_.LastLogin as LastLogin0_0_, this_.Online as Online0_0_, this_.Expansion as Expansion0_0_, this_.Mutetime as Mutetime0_0_, this_.Mutereason as Mutereason0_0_, this_.Muteby as Muteby0_0_, this_.Locale as Locale0_0_, this_.Os as Os0_0_, this_.Recruiter as Recruiter0_0_, this_.Salt as Salt0_0_ FROM
Account
this_ WHERE this_.Username = ?p0 ]
So I can see with automapping its mapping the class to the database.
I'm wanting to use the Automapping because I'm working with 3 different databases on 1 single server depending on where the data is so I have the classes in different namespaces hoping to pull 3 different sessions factories based on namespace as in the second one.
Because one time you add FluentNhibernate Mappings to the factory and the other time you try to add AutomapperMappings to the factory.
Both are completely different mapping strategies. I expect that for the fluent mappings you have all your classes mapped with ClassMap<T>
etc...
Automapper will not use your manually define Fluent Mappings, it will try to generate the mappings automatically based on your entities and some other settings and defaults.
The outcome can of cause something completely different... Therefore it might be that your queries do not work anymore with one or the other...
So for example your entity is Account
and with fluent nhibernate you mapped it to a table with a completely different name, e.g. MyAccounTable
, how should Automapper know about that, it will simply do the mapping assuming the table name is equal to the entity name...
Same for everything else...