Comments (14)
Hello @andrewpropago ,
If I look at this line:
onnection.BulkDelete<Discount>(discountsToDelete).BulkInsert<Discount>(toInsert);
You normally don't have to specify the generic type. I believe this line cause the issue since our library may find another mapping than Discount
even if you forced it.
Do you think it could be possible to provide us a project example?
I will at the same time ask one of my developers tomorrow to try to reproduce it.
Best Regards,
Jonathan
from dapper-plus.
I figured out the issue, it's because entity framework loads the data w/ a proxy object. We're converting slow entity interactions to dapper and dapper plus causing us to have a mix and match like this at times.
from dapper-plus.
Great,
Do you wish us to do something here? For example:
- Adding an option that will throw an error when a proxy type is found
- Adding an option that will discover the type behind the proxy type
Or something else?
Best Regards,
Jonathan
from dapper-plus.
Sorry, I've been on vacation.
It would be great if we had an option whether it be a bool passed into the operation or a DapperPlusManager setting that could be enabled to use proxy discovery.
Another possibility is just use the type from the generic call and ignore the object type all together. In my example above the BulkDelete call would ignore the crazy proxy type all together and just assume it's type Discount.
Getting the underlying type for a proxy object is relatively simple ObjectContext.GetObjectType(dbEntitymodifiedEntry.Entity.GetType()) but I'm not sure the overall impact always running that line of code would have.
Thank You,
Andrew
from dapper-plus.
Hello @andrewpropago ,
When doing this request, we found out that we already coded in the past a logic to handle EF Proxy type. However, this logic had some flaw. We improve it to get the .BaseType
which is what the ObjectContext.GetObjectType
do under the hood.
Could you try the v1.3.22 and let me know if that has worked?
If you still have the issue, could you provide us a project with the issue.
Best Regards,
Jonathan
from dapper-plus.
I've been digging in a bit more, and the exact line that's causing the error seems redundant.
specifically it's this this.Current = (IEnumerable) items.ToList(); from the method below.
/// <summary>Constructor.</summary>
/// <param name="oldActionSet">Set the old action belongs to.</param>
/// <param name="mapperKey">The mapper key.</param>
/// <param name="actionKind">The action kind.</param>
/// <param name="items">The items.</param>
/// <param name="selectors">A variable-length parameters list containing selectors.</param>
public DapperPlusActionSet(BaseDapperPlusActionSet oldActionSet, string mapperKey, DapperPlusActionKind actionKind, IEnumerable<TEntity> items, params Func<TEntity, object>[] selectors)
{
this.ImportConfiguration(oldActionSet);
if (items == null)
return;
this.Current = (IEnumerable<TEntity>) items.ToList<TEntity>();
this.AddAction(mapperKey, actionKind, this.Current);
if (selectors == null)
return;
List<List<object>> list = ((IEnumerable<Func<TEntity, object>>) selectors).Select<Func<TEntity, object>, List<object>>((Func<Func<TEntity, object>, List<object>>) (_param1 => this.Current.Select<TEntity, object>(_param1).ToList<object>())).ToList<List<object>>();
this.AddAction(mapperKey, actionKind, (IEnumerable<object>) list);
}
from dapper-plus.
So you still have an error?
Do you think you could provide a sample project ([email protected])? It will make easier for us then trying to reproducing this scenario.
from dapper-plus.
Yes, we're still having the error, I'm looking at your source vs the decompiled code and it seems like you don't need to .ToList() the items as it's already IEnumerable, which is what is causing the casting exception for reasons that are beyond me.
from dapper-plus.
The source are not up to date.
which is what is causing the casting exception for reasons that are beyond me
It's a different exception than the first one? The initial exception was about the DestinationTableName
and using a ToList
doesn't cause this.
from dapper-plus.
You are correct, I'm bouncing between projects. This is a different exception now, but still related to EntityFramework Proxy objects.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: Unable to cast object of type 'ArgosyModel.ESM_CART' to type 'System.Data.Entity.DynamicProxies.ESM_CART_6C8EC2607204AA2EDA768B3EAC0A3F93BF30E697F726FA93E35F84B18141FDB0'.
at System.Linq.Enumerable.d__971.MoveNext() at System.Collections.Generic.List
1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable
1 source)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Z.Dapper.Plus.DapperPlusAction.Execute()
at Z.Dapper.Plus.DapperPlusActionSet1..ctor(BaseDapperPlusActionSet oldActionSet, String mapperKey, DapperPlusActionKind actionKind, IEnumerable
1 items, Func2[] selectors) at Z.Dapper.Plus.DapperPlusActionSet
1.BulkMerge[T](String mapperKey, IEnumerable1 items, Func
2[] selectors)
at Z.Dapper.Plus.DapperPlusActionSet1.BulkMerge[T](IEnumerable
1 items, Func`2[] selectors)
from dapper-plus.
Thank, I believe I know how to easily reproduce it.
We will try it later today.
from dapper-plus.
Hello @andrewpropago ,
The v1.3.24 has been released.
We now call GetObjectType
to get the type from the proxy type pretty much everywhere.
Let me know if everything is fixed.
Best Regards,
Jonathan
from dapper-plus.
Jonathan,
Thanks for all the help, that works perfectly now!
Andrew
from dapper-plus.
Hello @andrewpropago ,
This issue will be closed since it has been resolved.
Feel free to reopen it if you feel otherwise.
Best Regards,
Jonathan
from dapper-plus.
Related Issues (20)
- A transport-level error for NVarchar(max) column when using auditing HOT 7
- Received an invalid column length from the bcp client for colid HOT 3
- Set ColumnSynchronizeDeleteKeySubsetExpression without .Entity<Whatever>()? HOT 4
- IndexOutOfRangeException on BulkMerge operations HOT 1
- ILogger not logging, but Console.WriteLine works? HOT 3
- Configure Merge for concurrency handling HOT 3
- Ids not coming back after first BulkInsert HOT 4
- Update trigger on target table causes BulkMerge to fail HOT 3
- Feature Request - suppress update if nothing changed. HOT 2
- BulkInsert doesn't generate primary key for multiple concurrent submission HOT 7
- Support for Sybase for Bulk Insert HOT 1
- Skip duplicate records on bulk insert HOT 5
- Avoid output HOT 7
- BulkInsert Postgres => An error occured while retrieving the InformationSchemaTable information. See the inner exception for details. HOT 4
- Dapper Plus can't map Id when use galera cluster HOT 3
- bulk insert very slow on mariadb version≥10.6.0 HOT 2
- PostgreSQL BulkMerge / BulkUpdate always returns all rows as update HOT 6
- Bulk Insert throws the exception 'Unknown data type' whenever inserting GUID to MySQL HOT 4
- Does this support DateOnly/TimeOnly? HOT 6
- Does this support Aot HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dapper-plus.