This question is locked. New answers and comments are not allowed.
I have been trying to experiment with the new UpdateAll extension method and it is just throwing an error while trying to run the update. I have a generic class that allows operations on the different classes generated by the OpenAccess designer and added a generic UpdateAll function that takes an expression to filter on and then the updateDescription that the UpdateAll method is looking for.
The rowSelector that I am passing in is filtering down to a single element on the primary key and the updateDescription is chained to update 3 different fields:
Using the profiler, the SQL that is generated appears like it should work:
However, it throws an error while executing:
"Failure: Batch Update failed on server: Expected=1/Got=2"
Any thoughts?
public
virtual
void
UpdateAll(System.Linq.Expressions.Expression<Func<T,
bool
>> rowSelector, Expression<Func<ExtensionMethods.UpdateDescription<T>, ExtensionMethods.UpdateDescription<T>>> updateDescription)
{
using
(var _entities =
new
Entities())
{
_entities.GetAll<T>().Where(rowSelector).UpdateAll(updateDescription);
}
}
The rowSelector that I am passing in is filtering down to a single element on the primary key and the updateDescription is chained to update 3 different fields:
ContactLogRepository.UpdateAll(x => x.Id == id,
x => x.Set(y => y.StatusId, y => 2)
.Set(y => y.ModifiedBy, y => "Some Name")
.Set(y => y.ModifiedOn, y => DateTime.Now));
Using the profiler, the SQL that is generated appears like it should work:
INSERT
INTO
#TMPBE81BDB03B154A72B54479AA2E (C0)
SELECT
a.[Id]
FROM
[dbo].[ContactLog] a
WHERE
a.[Id] = 1178435
UPDATE
x
SET
x.[StatusId] = 2,
x.[ModifiedBy] =
'Some Name'
,
x.[ModifiedOn] =
'6/27/2013 4:53:17 PM'
FROM
[dbo].[ContactLog] x
INNER
JOIN
#TMPBE81BDB03B154A72B54479AA2E t
ON
(x.[Id] = t.C0)
However, it throws an error while executing:
"Failure: Batch Update failed on server: Expected=1/Got=2"
Any thoughts?