这段代码会导致ArgumentException
,如下所示。奇怪的是,它只发生在单元测试执行期间。当应用程序运行时,此代码运行并运行。我想这可能意味着它是一个数据问题?我可以进一步了解它。
我已经尝试在联接中设置匿名类型,使其具有相同的列名,通过在两种匿名类型中执行A = ...
和B = ...
之类的操作,但这并不是&#39改变一切。
以下是我的询问:
var query =
(from account in db.AccountDetails
join team in db.Teams on new { account.CompanyId, account.TeamCode }
equals new { teams.CompanyId, teams.TeamCode } into groupedTeams
from team in groupedTeams.DefaultIfEmpty()
where account.CompanyId == message.CompanyId && account.ProcessId == message.ProcessId
select new
{
AccountDetail = account,
Team = groupedTeams.FirstOrDefault()
}
);
例外:
System.ArgumentException: Expression of type '' cannot be used for parameter of type 'System.Collections.Generic.IEnumerable`1[Packing.ColdCamperEtl.Business.Data.Elmer.Models.Tax]' of method 'System.Linq.IQueryable`1[<>f__AnonymousType0`2[Packing.ColdCamperEtl.Business.Data.Elmer.Models.AccountDetail,System.Collections.Generic.IEnumerable`1[Packing.ColdCamperEtl.Business.Data.Elmer.Models.Tax]]] GroupJoin[AccountDetail,Tax,<>f__AnonymousType1`2,<>f__AnonymousType0`2](System.Linq.IQueryable`1[Packing.ColdCamperEtl.Business.Data.Elmer.Models.AccountDetail], System.Collections.Generic.IEnumerable`1[Packing.ColdCamperEtl.Business.Data.Elmer.Models.Tax], System.Linq.Expressions.Expression`1[System.Func`2[Packing.ColdCamperEtl.Business.Data.Elmer.Models.AccountDetail,<>f__AnonymousType1`2[System.String,System.String]]], System.Linq.Expressions.Expression`1[System.Func`2[Packing.ColdCamperEtl.Business.Data.Elmer.Models.Tax,<>f__AnonymousType1`2[System.String,System.String]]], System.Linq.Expressions.Expression`1[System.Func`3[Packing.ColdCamperEtl.Business.Data.Elmer.Models.AccountDetail,System.Collections.Generic.IEnumerable`1[Packing.ColdCamperEtl.Business.Data.Elmer.Models.Tax],<>f__AnonymousType0`2[Packing.ColdCamperEtl.Business.Data.Elmer.Models.AccountDetail,System.Collections.Generic.IEnumerable`1[Packing.ColdCamperEtl.Business.Data.Elmer.Models.Tax]]]])'
at System.Linq.Expressions.Expression.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arg, ParameterInfo pi)
at System.Linq.Expressions.Expression.ValidateArgumentTypes(MethodBase method, ExpressionType nodeKind, ReadOnlyCollection`1& arguments)
at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments)
at System.Linq.Queryable.GroupJoin[TOuter,TInner,TKey,TResult](IQueryable`1 outer, IEnumerable`1 inner, Expression`1 outerKeySelector, Expression`1 innerKeySelector, Expression`1 resultSelector)
为什么会这样?