I'm using EF extension to do BulkSaveChanges
, and I'm using SQLite, everything works perfectly, fast saving, etc. The problem I'm having is that when saving Guids, it's as if BulkSaveChanges
is converting the Guids to TEXT first before saving, but the data type is BLOB, then when retrieved from the database through DbContext, GUIDs are not recognizable, my theory is that because the data is converted and the fact that the data type is BLOB, EF, couldn't convert it back to Guids implicitly.
Moreover, when using the EF's .SaveChanges
, everything is preserved, also retrieval is okay, but .SaveChanges
is slow.
Any help will be greatly appreciated.
So here's the link to the extension: https://entityframework-extensions.net/bulk-savechanges
Here's some screenshots of data being saved with .SaveChanges vs. .BulkSaveChanges
Saved with .SaveChanges:
Saved with .BulkSaveChanges:
I was able to make things work and able to live with this situation considering:
BulkSaveChanges
converts or should I say corrects the data before it's persisted, in this case converts it to TEXT.The problem however is that the data type remains BLOB, then when retrieved through EFCore, converting back to GUID implicitly, wouldn't work.
Upon analyzing the situation, I realized why can't I just define the data type of the GUIDs to TEXT? since BulkSaveChanges
does a conversion to TEXT anyway. And in that way, EFCore would be able to see that the GUIDs are saved as TEXT and not BLOB so it can know how to convert it back to GUID implicitly. Turned out, it's possible!
Here's what I did, I added these lines when we build the model through Fluent API for entities that contain GUIDs:
entityTypeBuilder
.Property(l => l.GUID)
.HasConversion<string>();
Building the model looks something like this:
public override void Build(ModelBuilder modelBuilder)
{
EntityTypeBuilder<Person> entityTypeBuilder =
modelBuilder.Entity<Person>();
entityTypeBuilder
.Property(l => l.GUID)
.HasConversion<string>();
}
Data type of GUIDs before:
Then after added these lines: