Search code examples
.net-corefluent-nhibernate

Fluent NhiberNate .net core 3.1 with sql server


Recently I started working on NhiberNate with .net core and try something simple I have a table like this:

public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
public virtual string LastName { get; set; }
public virtual int ClusterId { get; set; }**

Mapping like this:

Id(x => x.Id).Column("Id").GeneratedBy.GuidNative();
Map(x => x.Name);
Map(x => x.LastName);
Id(x => x.ClusterId);

Now Guid is the primary key, clusterid is just identity, I created table first and manually insert data in it, a guid created at the server-side like this

37815D12-C7BF-4575-9786-306D56DCB86D

But when I get the data from DB via postman or etc. Guid return like

00000000-0000-0000-0000-000000000000

I return data on the code like this return _session.Query<CustomEntity>().ToList();

I tried change mapping with .GeneratedBy.GuidComb(); and .GeneratedBy.Guid(); but doesn't work.


Solution

  • Change Id(x => x.ClusterId); to Map(x => x.ClusterId);. Having two Id mappings can cause all kinds of problems.