I have a class named User that inherits form AbpUser but I don't want to set CreatorUserId.
Since AbpUser inherits FullAuditEntity which implements ICreationAudited, it generates the CreatorUserId automatically. But the User class is used to register new users, for example when a user sign-up.
So, i get this error: The INSERT statement conflicted with the FOREIGN KEY SAME TABLE constraint "FK_dbo.AbpUsers_dbo.AbpUsers_CreatorUserId". The conflict occurred in database "OMC", table "dbo.AbpUsers", column 'Id'. The statement has been terminated.
How can i set CreaterUserId to null?
Thank you.
1 Answer(s)
-
0
Hi,
It should be null normally. Because, it gets the UserId from AbpSession.UserId. And if no user logged in, it should be null. Can you share the SQL executed?
Also, I can suggest a workaround. Override SetCreationAuditProperties (<a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/master/src/Abp.EntityFramework/EntityFramework/AbpDbContext.cs#L262">https://github.com/aspnetboilerplate/as ... xt.cs#L262</a>) method in your DbContext, check entity type and call the base method if it is not User.