Roar
Roar

Reputation: 2167

Fluent NHibernate map GUID type property NOT Identity

I have a guid property in my entity and i want to map it to guid field in MS SQL.

 public class SomeEntity
    {
        public virtual int Id { get; set; }
        public virtual Guid GUID { get; set; }
    }

and how can i map this to table and allow MS SQL generate this guid field
i've tried this

Id(x => x.Id).GeneratedBy.Identity();
Map(x => x.GUID).Unique().Not.Insert().Not.Update();

with no luck. The problem is when entity has been added it generates GUID but when i select it returns empty guid({00000000-0000-0000-0000-000000000000}).
also i've tried this

Map(x => x.GUID).Unique().ReadOnly();

again with no luck, so what is the solution? how to map to guid, which should be generated in MS SQL

Upvotes: 3

Views: 3266

Answers (1)

Roar
Roar

Reputation: 2167

my bad:

Map(x => x.GUID).Generated.Insert().ReadOnly();

works fine

Upvotes: 5

Related Questions