zzzprojects / EntityFramework-Extensions

Entity Framework Bulk Operations | Improve Entity Framework performance with Bulk SaveChanges, Insert, update, delete and merge for SQL Server, SQL Azure, SQL Compact, MySQL and SQLite.
https://entityframework-extensions.net
343 stars 57 forks source link

Add Support for InsertFromQuery + InMemory #477

Open groberts71 opened 2 years ago

groberts71 commented 2 years ago

Description

When attempting to use InsertFromQuery with the Microsoft InMemory database it throws the exception below.

Our unit tests at present are based on the InMemory database. We are hoping you might be able to add in support for this rather than us having to find a workaround (or not have unit tests).

Exception

Unhandled exception. System.Exception: Oops! This scenario is not yet support for InsertFromQuery + InMemory. at 1.(IQueryable1 , Action1 ) at 1.Execute(IQueryable1 query, Action1 batchInsertBuilder) at DbContextExtensions.[](IQueryable1 , Action1 ) at DbContextExtensions.[](IQueryable1 , String , String , String , Type , Expression1 ) at DbContextExtensions.InsertFromQuery[TEntity](IQueryable1 query, String tableName, Expression1 selectExpression) at InsertFromQuery.Program.Main() Command terminated by signal 6

Fiddle or Project (Optional)

https://dotnetfiddle.net/NfpB4n

Further technical details

JonathanMagnan commented 2 years ago

Hello @groberts71 ,

We indeed do not support that feature with InMemory yet.

We will look at what we can do.

Best Regards,

Jon

JonathanMagnan commented 2 years ago

Hello @groberts71 ,

My developer investigated this issue to find out what it will possible to do and what would be the limitation.

First, we would like to understand your scenario to see if we can support it or not.

You currently try to insert to the zcustomerdest table in your example. What's this memory table? It doesn't seem to be mapped anywhere. It's a table that exists via another DbSet such as public DbSet<CustomerDest> zcustomerdest { get; set; }? Or this is a new table that needs to be created?

Also how the table name is mapped (zcustomerdest)? The Table data annotation is not very friendly with InMemory provider, however mapping it using the API with the ModelBuilder (ToTable("zcustomerdest")`) seem to don't have problem

Best Regards,

Jon

groberts71 commented 2 years ago

Hi Jon,

In answer to your questions about the real scenario on our side - (1) The zcustomerdest table is pre-existing and does not need to be created.

(2) The example code was just for illustrative purposes and pared down to absolute bare basics. Maybe I went too far. in removing the destination table mapping.... :-) The zcustomerdest table is mapped within EF (i.e. there is a DbSet definition)

(3) We currently use the Table annotation, but can easily switch this to use Fluent API as part of any remediation effort to get this working.

Cheers, Glenn

JonathanMagnan commented 2 years ago

Thank @groberts71 for the additional information.

Just wanted to be sure that if we try to work on it that we could support your scenario ;)