Nhibernate Guid with PK MySQL
- by Andrew Kalashnikov
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!