Using Entity Framework's Fluent API, I can successfully insert a new row in the user's table using this code:
modelBuilder.Entity<User>().ToTable("Users");
modelBuilder.Entity<User>().HasKey(x => x.UserId);
However, I also want to set the CreatedBy field based on the Guid assigned to the UserId. The following code does not work:
modelBuilder.Entity<User>().Property(x => x.CreatedBy)
.HasDefaultValueSql("SCOPE_IDENTITY()");
I would appreciate any suggestions. Thanks.