I need to insert an entity by calling a stored procedure. The table in the database has a column called CreateDateTime
that has a default value of GetDate()
.
I do not let the stored procedure set / update the CreateDateTime
column.
When I call the dbcontext.SaveChanges()
it does indeed call my stored procedure and it inserts a row but then EF throws the following error:
A function mapping specifies a result column 'CreateDateTime' that the result set does not contain.
My DbContext
class has the following:
modelBuilder
.Entity<Test>()
.MapToStoredProcedures(s =>
s.Update(u => u.HasName("TestUpdate"))
.Delete(d => d.HasName("TestDelete"))
.Insert(i => i.HasName("TestInsert")));
The TestInsert
stored procedure is a simple INSERT INTO... SELECT SCOPE_IDENTITY()
On my Test
class I have a property like the following.
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public DateTime CreateDateTime { get; set; }