具有多个条件的数据表上的 LINQ
这个查询似乎不太高兴。有人有什么想法吗?
var results = from a in previousQuery
join b in dtCounties.AsEnumerable()
on new { a.CountyCode, a.StateCode } equals new {
b.Field<string>("COUNTYCODE"),
b.Field<string>("StateCode")
}
where b.Field<bool>("TrueOrFalse") == true
select new
{
CountyCode = a.CountyCode,
TrueOrFalse= b.Field<bool>("TrueOrFalse"),
Sum= a.Sum
};
我得到的错误是
“匿名类型成员声明符无效。必须使用成员赋值、简单名称或成员访问权限来声明匿名类型成员。”
对于连接右侧的 2 列(即 b.Field
和 b.Field
)。
This query just doesnt seem to be very happy. Any ideas anyone?
var results = from a in previousQuery
join b in dtCounties.AsEnumerable()
on new { a.CountyCode, a.StateCode } equals new {
b.Field<string>("COUNTYCODE"),
b.Field<string>("StateCode")
}
where b.Field<bool>("TrueOrFalse") == true
select new
{
CountyCode = a.CountyCode,
TrueOrFalse= b.Field<bool>("TrueOrFalse"),
Sum= a.Sum
};
The error I get is
"Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access."
for the 2 columns in the right hand side of the join (ie b.Field<string>("COUNTYCODE")
and b.Field<string>("StateCode")
).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这只是 C# 语法问题,而不是 LINQ 本身。考虑以下事项:
为了澄清一下,这是上述结果:
This is just a C# syntax issue, not LINQ itself. Consider the following:
Just to clarify, here is the result of the above:
您需要将字段运算符的结果分配给命名属性。
试试这个:
You need to assign the results of the field operator to named properties.
Try this: