NHibernate and MySql is inserting and Selecting, not updating
- by Chris Brandsma
Something strange is going on with NHibernate for me. I can select, and I can insert. But I can't do and update against MySql.
Here is my domain class
public class UserAccount
{
public virtual int Id { get; set; }
public virtual string UserName { get; set; }
public virtual string Password { get; set; }
public virtual bool Enabled { get; set; }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual string Phone { get; set; }
public virtual DateTime? DeletedDate { get; set; }
public virtual UserAccount DeletedBy { get; set; }
}
Fluent Mapping
public class UserAccountMap : ClassMap<UserAccount>
{
public UserAccountMap()
{
Table("UserAccount");
Id(x => x.Id);
Map(x => x.UserName);
Map(x => x.Password);
Map(x => x.FirstName);
Map(x => x.LastName);
Map(x => x.Phone);
Map(x => x.DeletedDate);
Map(x => x.Enabled);
}
}
Here is how I'm creating my Session Factory
var dbconfig = MySQLConfiguration
.Standard
.ShowSql()
.ConnectionString(a => a.FromAppSetting("MySqlConnStr"));
FluentConfiguration config = Fluently.Configure()
.Database(dbconfig)
.Mappings(m =>
{
var mapping = m.FluentMappings.AddFromAssemblyOf<TransactionDetail>();
mapping.ExportTo(mappingdir);
});
and this is my NHibernate code:
using (var trans = Session.BeginTransaction())
{
var user = GetById(userId);
user.Enabled = false;
user.DeletedDate = DateTime.Now;
user.UserName = "deleted_" + user.UserName;
user.Password = "--removed--";
Session.Update(user);
trans.Commit();
}
No exceptions are being thrown. No queries are being logged. Nothing.