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

BatchUpdate number increment failing in SQLite a PostgreSQL

Open ondrasvoboda opened this issue 7 years ago • 9 comments

I need to increment number in EF6 using Batch update in SQLite and PostgreSQL databases. Something like this:

update persons set number = number + 1;

I tried:

db.Persons.Update(p => new Person() { Number = p.Number + 1 });

But it is failing in both databases I'm using. Simple number update works though.

db.Persons.Update(p => new Person() { Number = 10 });

Can you please have a look on it? Maybe I'm doing something wrong.

Thank you

ondrasvoboda avatar May 30 '18 13:05 ondrasvoboda

same issue, need help too.

lousaibiao avatar May 30 '18 15:05 lousaibiao

Here is the exception detail: MySql.Data.MySqlClient.MySqlException: 'Unknown column 'w.xxx' in 'field list'' Inner Exception MySqlException: Unknown column 'w.xxx' in 'field list'

lousaibiao avatar May 30 '18 15:05 lousaibiao

Hello @ondrasvoboda , @lousaibiao ,

Unfortunately using this kind of expression is not supported with SQLite while some other providers such as SQL Server support it.

That's due because we didn't find how to make an UPDATE with JOIN in SQLite.

If you have an idea how to make this kind of UPDATE, just let us know and we will try. Keep in mind, we cannot use sub-query like in this answer: https://stackoverflow.com/a/21074659/5619143 in the SET statement since we don't fully control the query.

Best Regards,

Jonathan

JonathanMagnan avatar May 31 '18 17:05 JonathanMagnan

Thank you for your answer. I use mysql this time, and checked that this sub-query is valid in mysql. So, if it possible that making this kind of expression only works in several sql, like ms-sql, mysql and so on.

lousaibiao avatar Jun 01 '18 01:06 lousaibiao

Isn't there a way how to do it without join? Because join is not really needed in this case.

Can this be used for PostgreSQL? https://stackoverflow.com/questions/7869592/how-to-do-an-update-join-in-postgresql

ondrasvoboda avatar Jun 04 '18 11:06 ondrasvoboda

Hello @ondrasvoboda ,

We will look at it and the reason why we didn't used this syntax in the first place.

Best Regards,

Jonathan

JonathanMagnan avatar Jun 07 '18 22:06 JonathanMagnan

Hi, did you find anything new regarding this issue?

ondrasvoboda avatar Nov 15 '18 10:11 ondrasvoboda

Hello @ondrasvoboda ,

We are currently completing re-writing that features in EF Classic (https://entityframework-classic.net/),

Once we complete it here, we will start to move the new code in EFE (https://entityframework-extensions.net/) and support other providers like PostgreSQL (it will be available for free and will replace the Batch Update for EF Plus)

So the code will be soon be all modified.

We hope that the new code will be released on next month.

Best Regards,

Jonathan

JonathanMagnan avatar Nov 15 '18 13:11 JonathanMagnan

Cool, thanks for the info.

ondrasvoboda avatar Nov 15 '18 13:11 ondrasvoboda