var firstBlog = new Blog { Url = "http://blogs.msdn.com/adonet" };
db.Add(firstBlog);
when SaveChanges() is called, issues the following SQL statement (which was setup in the JsonCommand.ExecuteDbDataReader() call):
INSERT INTO "Blogs" ("Url") VALUES (@p0); SELECT "BlogId" FROM "Blogs" WHERE ROW_COUNT() = 1 AND "BlogId"=LAST_INSERT_ID();
When processing this, the INSERT statement executes fine, but the table schema determined at that point in time, only has a "Blogs" column, because from that insert statement this is all that is known. The processing look in the fields of the SELECT and in the WHERE clause. Also, it could be a SELECT statement that has no FROM clause (which is processed in a different code path).
The enhancement here, would be to preprocess both SQL statements before the INSERT is called and provide a hint to the INSERT, that there is a BlogId field, because it is used in the SELECT WHERE clause.
In EF Core, on the Getting Started unit test, (specifically https://github.com/Servant-Software-LLC/EFCore.FileBased.Providers/blob/main/tests/EFCore.Json.Tests/FolderAsDatabase/JsonGettingStartedTests.cs#L37), the setup of the unit test starts from an empty table. The first addition of an entity with the following code:
when SaveChanges() is called, issues the following SQL statement (which was setup in the JsonCommand.ExecuteDbDataReader() call):
INSERT INTO "Blogs" ("Url") VALUES (@p0); SELECT "BlogId" FROM "Blogs" WHERE ROW_COUNT() = 1 AND "BlogId"=LAST_INSERT_ID();
When processing this, the INSERT statement executes fine, but the table schema determined at that point in time, only has a "Blogs" column, because from that insert statement this is all that is known. The processing look in the fields of the SELECT and in the WHERE clause. Also, it could be a SELECT statement that has no FROM clause (which is processed in a different code path).
The enhancement here, would be to preprocess both SQL statements before the INSERT is called and provide a hint to the INSERT, that there is a BlogId field, because it is used in the SELECT WHERE clause.