Problem with Entity Framework extensions .BulkSaveChanges - Saving Guid

.net-core entity-framework-core sqlbulkcopy sqlite

Question

Using the EF extension, IBulkSaveChanges I'm using SQLite, and everything works well, storing data quickly, etc. My issue is that after storing Guids, it seems as ifBulkSaveChanges is first converting the Guids to TEXT before saving, but the data type is BLOB; as a result, when the data is retrieved from the database through DbContext, the GUIDs are not recognized. My theory is that because the data has been converted and the data type is BLOB, EF is unable to convert it back to Guids implicitly.

Furthermore, while using the EF's.SaveChanges All information is saved, and recovery is successful, however.SaveChanges and slow.

Any assistance would be highly appreciated.

Therefore, this is the URL for the extension: https://entityframework-extensions.net/bulk-savechanges

Here are some images of data being stored. vs SaveChanges. BulkSaveChanges

Saving changes with.SaveChanges:

enter image description here

with.BulkSaveChanges: saved

enter image description here

1
0
4/16/2019 3:56:06 AM

Accepted Answer

I was able to make things work and deal with this circumstance taking into account:

  1. That SQLite does not handle GUIDs and that it classifies unknown data as a BLOB.
  2. That BulkSaveChanges changes the data—or should I say corrects the data—to TEXT before it is saved.

The issue is that the data type is still BLOB, therefore implicit conversion to GUID when fetched using EFCore wouldn't function.

After doing some analysis, I understood why I couldn't simply set the GUIDs' data type to TEXT. sinceBulkSaveChanges performs a TEXT conversion nevertheless. And in doing so, EFCore would be able to determine that the GUIDs are stored as TEXT rather than BLOB so that it would understand how to implicitly convert them back to GUID. It turned out to be doable!

As we construct the model using the Fluent API for entities that include GUIDs, I added the following lines.

entityTypeBuilder
    .Property(l => l.GUID)
    .HasConversion<string>();

The process of building the model looks like this:

public override void Build(ModelBuilder modelBuilder)
{
    EntityTypeBuilder<Person> entityTypeBuilder =
        modelBuilder.Entity<Person>();

    entityTypeBuilder
        .Property(l => l.GUID)
        .HasConversion<string>();
}

prior data type of GUIDs:

enter image description here

then added the following lines:

enter image description here

1
4/17/2019 4:20:43 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow