Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 253
Roar Avatar asked Jan 17 '26 05:01

Roar


1 Answers

my bad:

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

works fine

like image 168
Roar Avatar answered Jan 19 '26 19:01

Roar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!