views:

124

answers:

1

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.

A: 

Hi Chris,

did this ever get solved, I have the same issue.

cheers,

A

Andy LifeBrixx
This was a while ago, but I think there was a bug with the MySQL provider for NHibernate at the time. You might check to make sure you are running the latest version. I had to modify the NHibernate source to get this to work.
Chris Brandsma
Cheers for the reply Chris, my problem was different, see how I fixed it here: http://stackoverflow.com/questions/2789122/nhibernate-will-insert-but-not-update-after-move-to-host-with-shared-server-runni/2822967#2822967
Andy LifeBrixx