Nhibernate Guid with PK MySQL

Posted by Andrew Kalashnikov on Stack Overflow See other posts from Stack Overflow or by Andrew Kalashnikov
Published on 2010-03-11T09:49:16Z Indexed on 2010/03/12 6:57 UTC
Read the original article Hit count: 711

Filed under:
|
|
|

Hello colleagues. I've got a question. I use NHibernate with MySql. At my entities I use Id(PK) for my business-logic usage and Guid(for replication). So my BaseDomain:

 public class BaseDomain
 {
    public virtual int Id { get; set; }
    public virtual Guid Guid { get; set; }
    public class Properties
    {
        public const string Id = "Id";
        public const string Guid = "Guid";
    }
    public BaseDomain() { }
 }

My usage domain:

public class ActivityCategory : BaseDomain
{
    public ActivityCategory() { }
    public virtual string Name { get; set; }
    public new class Properties
    {
        public const string Id = "Id";
        public const string Guid = "Guid";
        public const string Name = "Name";
        private Properties() { }
    }
}

Mapping:

 <class name="ActivityCategory, Clients.Core" table='Activity_category'>
   <id name="Id" unsaved-value="0" type="int">
      <column name="Id" not-null="true"/>
      <generator class="native"/>
   </id>
   <property name="Guid"/>
   <property name="Name"/>
 </class>

But when I insert my entity:

[Test]
    public void Test()
    {
        ActivityCategory ac = new ActivityCategory();
        ac.Name = "Test";
        using (var repo = new Repository<ActivityCategory>())
            repo.Save(ac);
    }

I always get '00000000-0000-0000-0000-000000000000' at my Guid field. What should I do for generate right Guid. May be mapping?

Thanks a lot!

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about mysql