EntityFramework-Plus icon indicating copy to clipboard operation
EntityFramework-Plus copied to clipboard

Object reference not set to an instance of an object for BatchDelete

Open wschay opened this issue 8 years ago • 14 comments

Hi,

I am trying to use the basic BatchDelete functionality on EFCore for MySql

My code is as follows: context.Users.Where(u => u.Email == null).Delete();

When running the statement I receive Object reference not set to an instance of an object for the type. See partial stack trace below: System.NullReferenceException: Object reference not set to an instance of an object. at System.Object.GetType() at Z.EntityFramework.Plus.BatchDelete.Execute[T](IQueryable1 query)`

Please advise what am I doing wrong?

Many thanks,

Warren

wschay avatar Jul 11 '17 08:07 wschay

Hello @wschay ,

Thank you for reporting.

Looking at the code, MySQL is currently only supported for EF5 and EF6 which explains why you get this error under EFCore.

We will try to fix this issue Wednesday.

Best Regards,

Jonathan

JonathanMagnan avatar Jul 11 '17 11:07 JonathanMagnan

Hello @wschay ,

We are currently implementing the support for Batch Delete && Batch Update.

We tested both methods and they are currently working fine in our dev environment.

However, the solution depends on the third party library used for MySQL.

Could you provide us the library name you are using? By example:

  • https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql
  • https://www.nuget.org/packages/SapientGuardian.EntityFrameworkCore.MySql/
  • Another one?

Best Regards,

Jonathan

JonathanMagnan avatar Jul 11 '17 20:07 JonathanMagnan

Hi Jonathan,

I'm currently using the pre-release of the official mysql provider.

https://docs.microsoft.com/en-us/ef/core/providers/mysql/

Many thanks,

Warren

Sent from my Samsung Galaxy smartphone.

-------- Original message -------- From: Jonathan Magnan [email protected] Date: 2017/07/11 10:53 PM (GMT+02:00) To: zzzprojects/EntityFramework-Plus [email protected] Cc: Warren Schay [email protected], Mention [email protected] Subject: Re: [zzzprojects/EntityFramework-Plus] Object reference not set to an instance of an object for BatchDelete (#182)

Hello @wschayhttps://github.com/wschay ,

We are currently implementing the support for Batch Delete && Batch Update.

We tested both methods and they are currently working fine in our dev environment.

However, the solution depends on the third party library used for MySQL.

Could you provide us the library name you are using? By example:

  • https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql
  • https://www.nuget.org/packages/SapientGuardian.EntityFrameworkCore.MySql/
  • Another one?

Best Regards,

Jonathan

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/zzzprojects/EntityFramework-Plus/issues/182#issuecomment-314568325, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AcrbbNplGg32_nu1cxKZ_y_Sxkqb6Kzlks5sM-DHgaJpZM4OT7JA.

wschay avatar Jul 11 '17 21:07 wschay

Thank you,

We will update the code tomorrow to also support it and release the fix

Best Regards,

Jonathan

JonathanMagnan avatar Jul 11 '17 21:07 JonathanMagnan

Hello @wschay ,

Are you aware how to fix this following error?

FileLoadException: Could not load file or assembly 'MySql.Data, Version=6.10.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)

It looks I'm not alone having this issue. https://forums.mysql.com/read.php?38,650219,650868

If you don't know, that's fine. I will release a blind version and pray it will work ;)

Best Regards,

Jonathan

JonathanMagnan avatar Jul 12 '17 19:07 JonathanMagnan

Hi Jonathan,

Unfortunately, I haven't come across that error before :(

Regards,

Warren

Sent from my Samsung Galaxy smartphone.

-------- Original message -------- From: Jonathan Magnan [email protected] Date: 2017/07/12 9:11 PM (GMT+02:00) To: zzzprojects/EntityFramework-Plus [email protected] Cc: Warren Schay [email protected], Mention [email protected] Subject: Re: [zzzprojects/EntityFramework-Plus] Object reference not set to an instance of an object for BatchDelete (#182)

Hello @wschayhttps://github.com/wschay ,

Are you aware how to fix this following error?

FileLoadException: Could not load file or assembly 'MySql.Data, Version=6.10.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)

It looks I'm not alone having this issue. https://forums.mysql.com/read.php?38,650219,650868

If you don't know, that's fine. I will release a blind version and pray it will work ;)

Best Regards,

Jonathan

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/zzzprojects/EntityFramework-Plus/issues/182#issuecomment-314868226, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AcrbbBmdrZGfSHJTDKlnOxJDN16ZiWmJks5sNRphgaJpZM4OT7JA.

wschay avatar Jul 12 '17 19:07 wschay

Hi @wschay

Just came across this error around BatchUpdate, with DotNet Core 2 preview 2:

Could not load type 'Microsoft.EntityFrameworkCore.Query.Internal.RelationalQueryContextFactory' from assembly 'Microsoft.EntityFrameworkCore.Relational, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
  Arborescence des appels de procédure :
   at Z.EntityFramework.Plus.InternalExtensions.GetDbContext[T](IQueryable`1 source)
   at Z.EntityFramework.Plus.BatchUpdate.Execute[T](IQueryable`1 query, Expression`1 updateFactory) 

I still have the error with version 1.6.5.

Regards, Thibault

tvoisin avatar Jul 13 '17 14:07 tvoisin

Bonjour @tvoisin ,

Could you try by adding assemblyBinding in your config file

 <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.EntityFrameworkCore" culture="neutral" publicKeyToken="adb9793829ddae60" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="2.0.0.0" />"
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.EntityFrameworkCore.Relational" culture="neutral" publicKeyToken="adb9793829ddae60" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="2.0.0.0" />"
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" culture="neutral" publicKeyToken="adb9793829ddae60" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="2.0.0.0" />"
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

I believe this issue is more related because our library is compiled with version 1.x but also work with 2.x ... We may need to release a version under 2.x probably in the future to avoid this kind of error.

Best Regards,

Jonathan

JonathanMagnan avatar Jul 13 '17 15:07 JonathanMagnan

Hello @wschay ,

The v1.6.6 has been released.

Unfortunately, we only successfully tested it with Pomelo so perhaps that's still not fully working with the mysql provider you are using due to a typing mistake.

Please, let us know if that work or not and report us any error.

Best Regards,

Jonathan

JonathanMagnan avatar Jul 16 '17 23:07 JonathanMagnan

Hi @wschay,

The binding redirect trick did not work, so I tried recompiling using Microsoft.EntityFrameworkCore.Relational 2.0.0-preview2-final (on framework standard 2.0). Some interfaces have been broken between the 2 versions, but I managed to have the whole thing working: I will make you a pull request with those changes.

tvoisin avatar Jul 17 '17 13:07 tvoisin

Hello @tvoisin ,

The v1.6.11 has been released supporting EF Core 2.0 stable

Best Regards,

Jonathan

JonathanMagnan avatar Aug 18 '17 00:08 JonathanMagnan

On the current version, I caught this error. What to do? MySql Pomelo 3.1

ivanmem avatar Apr 21 '20 14:04 ivanmem

Hello @xeleoss ,

Could you provide a runnable project with this issue?

Best Regards,

Jon

JonathanMagnan avatar Apr 22 '20 02:04 JonathanMagnan

Hello @xeleoss ,

Could you provide a runnable project with this issue?

Best Regards,

Jon

The project is no longer there. The error was on ubuntu 18.04. Before that, it was tested on windows 10 and worked.

ivanmem avatar May 01 '20 15:05 ivanmem