Я пытаюсь обновить таблицу Registry со списком моих собственных объектов класса. Я обнаружил, что я должен использовать временные таблицы для слияния с моей коллекцией.
var tsource = Content.GroupBy(l => l.CardId).Select(s => new DocumentContent
{
CardId = s.Key,
Quantity = s.Sum(c=> c.Quantity),
}).ToList();
var tempTable = db.CreateTable<DocumentContent>("#tmp");
tempTable.BulkCopy(tsource);
var source = tempTable.Select(s => s);
и затем объединение этой временной таблицы с целевой таблицей.
db.GetTable<Registry>()
.Merge()
.Using(source)
.On(s => s.CardId, f => f.CardId)
.UpdateWhenMatched((t, s) => new Registry()
{
Quantity = t.Quantity + s.Quantity,
})
.Merge();
Но когда я использую операцию слияния, я получаю InvalidCastException в
LinqToDB.Linq.Builder.AllJoinsLinqBuilder.BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
в \ LinqToDB \ Linq \ Builder \ AllJoinsLinqBuilder.cs: строка 44
В чем причина этого? Что не так?
UPD
трассировка стека
at LinqToDB.Linq.Builder.AllJoinsLinqBuilder.BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo) in C:\projects\linq2db\Source\LinqToDB\Linq\Builder\AllJoinsLinqBuilder.cs:line 44
at LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(BuildInfo buildInfo) in C:\projects\linq2db\Source\LinqToDB\Linq\Builder\ExpressionBuilder.cs:line 175
at LinqToDB.Linq.Builder.ContextParser.BuildSequence(ExpressionBuilder builder, BuildInfo buildInfo) in C:\projects\linq2db\Source\LinqToDB\Linq\Builder\ContextParser.cs:line 22
at LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(BuildInfo buildInfo) in C:\projects\linq2db\Source\LinqToDB\Linq\Builder\ExpressionBuilder.cs:line 175
at LinqToDB.Linq.Builder.ExpressionBuilder.Build[T]() in C:\projects\linq2db\Source\LinqToDB\Linq\Builder\ExpressionBuilder.cs:line 146
at LinqToDB.Linq.Query`1.CreateQuery(IDataContext dataContext, Expression expr) in C:\projects\linq2db\Source\LinqToDB\Linq\Query.cs:line 280
at LinqToDB.Linq.Query`1.GetQuery(IDataContext dataContext, Expression& expr) in C:\projects\linq2db\Source\LinqToDB\Linq\Query.cs:line 233
at LinqToDB.Linq.ExpressionQuery`1.GetQuery(Expression& expression, Boolean cache) in C:\projects\linq2db\Source\LinqToDB\Linq\ExpressionQuery.cs:line 84
at LinqToDB.Linq.ExpressionQuery`1.System.Linq.IQueryProvider.Execute[TResult](Expression expression) in C:\projects\linq2db\Source\LinqToDB\Linq\ExpressionQuery.cs:line 165
at LinqToDB.DataProvider.BasicMergeBuilder`2.BuildPredicateByKeys(Type keyType, Expression targetKey, Expression sourceKey) in C:\projects\linq2db\Source\LinqToDB\DataProvider\BasicMergeBuilder.cs:line 97
at LinqToDB.DataProvider.BasicMergeBuilder`2.BuildMatch() in C:\projects\linq2db\Source\LinqToDB\DataProvider\BasicMergeBuilder.cs:line 561
at LinqToDB.DataProvider.BasicMergeBuilder`2.BuildCommandText() in C:\projects\linq2db\Source\LinqToDB\DataProvider\BasicMergeBuilder.cs:line 646
at LinqToDB.DataProvider.BasicMergeBuilder`2.BuildCommand() in C:\projects\linq2db\Source\LinqToDB\DataProvider\BasicMergeBuilder.cs:line 1265
at LinqToDB.DataProvider.DataProviderBase.Merge[TTarget,TSource](DataConnection dataConnection, IMergeable`2 merge) in C:\projects\linq2db\Source\LinqToDB\DataProvider\DataProviderBase.cs:line 481
at WsMVC.Core.ExpenditurePaper.Incur() in D:\Projects\ProjMVC\MVC\Core\Document.cs:line 225
значение ex.ToString ()
System.InvalidCastException: Specified cast is not valid.
at LinqToDB.Linq.Builder.AllJoinsLinqBuilder.BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo) in C:\projects\linq2db\Source\LinqToDB\Linq\Builder\AllJoinsLinqBuilder.cs:line 44
at LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(BuildInfo buildInfo) in C:\projects\linq2db\Source\LinqToDB\Linq\Builder\ExpressionBuilder.cs:line 175
at LinqToDB.Linq.Builder.ContextParser.BuildSequence(ExpressionBuilder builder, BuildInfo buildInfo) in C:\projects\linq2db\Source\LinqToDB\Linq\Builder\ContextParser.cs:line 22
at LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(BuildInfo buildInfo) in C:\projects\linq2db\Source\LinqToDB\Linq\Builder\ExpressionBuilder.cs:line 175
at LinqToDB.Linq.Builder.ExpressionBuilder.Build[T]() in C:\projects\linq2db\Source\LinqToDB\Linq\Builder\ExpressionBuilder.cs:line 146
at LinqToDB.Linq.Query`1.CreateQuery(IDataContext dataContext, Expression expr) in C:\projects\linq2db\Source\LinqToDB\Linq\Query.cs:line 280
at LinqToDB.Linq.Query`1.GetQuery(IDataContext dataContext, Expression& expr) in C:\projects\linq2db\Source\LinqToDB\Linq\Query.cs:line 233
at LinqToDB.Linq.ExpressionQuery`1.GetQuery(Expression& expression, Boolean cache) in C:\projects\linq2db\Source\LinqToDB\Linq\ExpressionQuery.cs:line 84
at LinqToDB.Linq.ExpressionQuery`1.System.Linq.IQueryProvider.Execute[TResult](Expression expression) in C:\projects\linq2db\Source\LinqToDB\Linq\ExpressionQuery.cs:line 165
at LinqToDB.DataProvider.BasicMergeBuilder`2.BuildPredicateByKeys(Type keyType, Expression targetKey, Expression sourceKey) in C:\projects\linq2db\Source\LinqToDB\DataProvider\BasicMergeBuilder.cs:line 97
at LinqToDB.DataProvider.BasicMergeBuilder`2.BuildMatch() in C:\projects\linq2db\Source\LinqToDB\DataProvider\BasicMergeBuilder.cs:line 561
at LinqToDB.DataProvider.BasicMergeBuilder`2.BuildCommandText() in C:\projects\linq2db\Source\LinqToDB\DataProvider\BasicMergeBuilder.cs:line 646
at LinqToDB.DataProvider.BasicMergeBuilder`2.BuildCommand() in C:\projects\linq2db\Source\LinqToDB\DataProvider\BasicMergeBuilder.cs:line 1265
at LinqToDB.DataProvider.DataProviderBase.Merge[TTarget,TSource](DataConnection dataConnection, IMergeable`2 merge) in C:\projects\linq2db\Source\LinqToDB\DataProvider\DataProviderBase.cs:line 481
at WsMVC.Core.ExpenditurePaper.Incur() in D:\Projects\ProjMVC\WsMVC\Core\Document.cs:line 225