linq2db / LinqToDB.Identity

ASP.NET Core Identity provider that uses LinqToDB.
https://linq2db.github.io/
MIT License
46 stars 9 forks source link

Id field of IdentityUser is missing an IdentityAttribute #10

Closed hahn-kev closed 6 years ago

hahn-kev commented 7 years ago

The issue I found is that when I'm using IdentityUser when I insert into the database (or generate the table) the Id column doesn't get setup properly, and when I register a new user an Id isn't getting created from a sequence because it doesn't have the IdentityAttribute.

In order to work around this issue I've had to use the FluentMappingBuilder to add the Identity attribute to the Id field. Like so: MappingSchema.GetFluentMappingBuilder().Entity<IdentityUser<int>>().HasIdentity(user => user.Id)

I'm still a bit new to Linq2Db so I'm not sure if there's a reason not to add that in all cases, however I think we should at least document that you might need to use the above snippet to configure your user properly.

ili commented 6 years ago

@hahn-kev thanks for your comment!

In general you are right - by default we do not put identity attribute on POCOs. This is because Id can also be string\guid\etc.

So your solution is absolutely right - using GetFluentMappingBuilder at Startup.cs.

P.S. I will document this