I have created an entity model in Entity Developer and code is generated using the dbcontext template with "fluent" and "database independent" attributes set to true.
In that model I have an entity called "RetailerCategory" and the generated fluent mapping seems to be just fine.
Something along these lines (relevant parts only):
Code: Select all
modelBuilder.Entity()
.HasKey(p => new { p.RetailerCategory_Id })
.ToTable("KAKATEGORIER", "dbschema");
// Properties:
modelBuilder.Entity()
.Property(p => p.RetailerCategory_Id)
.IsRequired();
However if I try to add a new instance of the "RetailerCategory" entity (with an Id set manually) to the context and save changes I get an Oracle error, saying the value cannot be null.
That is not so strange because the SQL (taken from DbMonitor) looks like this:
Code: Select all
DECLARE
updatedRowid ROWID;
BEGIN
INSERT INTO dbschema.KAKATEGORIER(KAKODE, KATEXT, KAPROVKODE, KAPAKKAVGIFT, KAEDAT, KASIGN, KADGRFORFALL, KAFASTFORFALL, KAINSTITUSJON)
VALUES (:p0, :p1, NULL, :p2, NULL, NULL, :p3, NULL, NULL)
RETURNING ROWID INTO updatedRowid;
OPEN :outParameter FOR SELECT RetailerCategory_Id FROM infosoft.KAKATEGORIER WHERE ROWID = updatedRowid;
END;
So how do I go about manually inserting the primary key when using database independent fluentmapping?