Coder Social home page Coder Social logo

Comments (14)

JonathanMagnan avatar JonathanMagnan commented on May 18, 2024

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.

andrewpropago avatar andrewpropago commented on May 18, 2024

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.

JonathanMagnan avatar JonathanMagnan commented on May 18, 2024

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.

andrewpropago avatar andrewpropago commented on May 18, 2024

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.

JonathanMagnan avatar JonathanMagnan commented on May 18, 2024

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.

andrewpropago avatar andrewpropago commented on May 18, 2024

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.

JonathanMagnan avatar JonathanMagnan commented on May 18, 2024

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.

andrewpropago avatar andrewpropago commented on May 18, 2024

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.

JonathanMagnan avatar JonathanMagnan commented on May 18, 2024

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.

andrewpropago avatar andrewpropago commented on May 18, 2024

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.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 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, IEnumerable1 items, Func2[] selectors) at Z.Dapper.Plus.DapperPlusActionSet1.BulkMerge[T](String mapperKey, IEnumerable1 items, Func2[] selectors)
at Z.Dapper.Plus.DapperPlusActionSet1.BulkMerge[T](IEnumerable1 items, Func`2[] selectors)

from dapper-plus.

JonathanMagnan avatar JonathanMagnan commented on May 18, 2024

Thank, I believe I know how to easily reproduce it.

We will try it later today.

from dapper-plus.

JonathanMagnan avatar JonathanMagnan commented on May 18, 2024

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.

andrewpropago avatar andrewpropago commented on May 18, 2024

Jonathan,
Thanks for all the help, that works perfectly now!

Andrew

from dapper-plus.

JonathanMagnan avatar JonathanMagnan commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.