I have 2 tables
User (PK -> UserID -> Identity) and
UserRole (PK -> UserRoleID -> Identity)
Inorder to create a new user and userrole this is what i am doing:
UserEntity user = new UserEntity();
UserRoleEntity ur = new UserRoleEntity();
user.UserName = "Test";
ur.UserId = user.UserId;
ur.RoleId = 1;
ur.User = user;
Now to save recursively
user.Save(true);
I get this exception:
- {"An exception was caught during the execution of an action query: Line 1: Incorrect syntax near ')'.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception." } System.Exception
Here is the profiler info:
declare @P1 int
set @P1=NULL
exec sp_executesql N'INSERT INTO [dbo].[Users] () VALUES ();SELECT @UserId=SCOPE_IDENTITY()', N'@UserId int output', @UserId = @P1 output
select @P1
Obviously p1 cannot be null.
Does this mean before saving User i need to first find out an id which does not exist in User table and then set the Id first followed by saving it or if there is an alternative approach for this.
Please let me know.