Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wmwood opened this issue Jul 26, 2019 · 3 comments

Comments

@wmwood
Copy link

wmwood commented Jul 26, 2019

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."

@RudeySH
Copy link
Owner

RudeySH commented Aug 16, 2019

Can you provide a code example that reproduces this issue?

@DusanSenior
Copy link

DusanSenior commented Sep 2, 2019

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

@austinw-fineart
Copy link

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants