EntityFramework.Utilities icon indicating copy to clipboard operation
EntityFramework.Utilities copied to clipboard

Update By Query: The variable name '@p__linq__0' has already been declared.

Open wmwood opened this issue 5 years ago • 3 comments

When ever I try to do a update by query, i get the following Exception message:

"The variable name '@p__linq__0' has already been declared. Variable names must be unique within a query batch or stored procedure."

wmwood avatar Jul 26 '19 00:07 wmwood

Can you provide a code example that reproduces this issue?

RudeySH avatar Aug 16 '19 14:08 RudeySH

Hi, I have similar problem, there is an example (like your example EFBatchOperation.For(db, db.Comments).Where(x => x.Text == "a").Update(x => x.Reads, x => x.Reads + 1);)

var value1 = 1 var value2 = 2 EFBatchOperation.For(db, db.Comments) .Where(x => x.Reads == value1) .Update(x => x.Reads, x => value2); The variable name '@p__linq__0' has already been declared... is thrown Note: If I have used constant instead of variables all is OK But I would like to execute update Comments set Reads = @2 where Reads = @1 Thanks Dusan

DusanSenior avatar Sep 02 '19 08:09 DusanSenior

Another example:

var userId = 1;
var now = DateTime.UtcNow;
EFBatchOperation.For(db, db.Comments)
    .Where(x => x.UserId == userId && x.ReadAt == null)
    .Update(x => x.ReadAt, x => now);

austinw-fineart avatar Aug 18 '20 06:08 austinw-fineart