3

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.

0

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot ,this solved my problem.I guess I just misunderstood the id consept for nhibernate mapping through the samples ,cuz ClusterId is not primary key but identity and has autoincrement on my table.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.