名称为“CON”不存在于当前上下文存在 [英] The name 'con' does not exist in the current context

查看:213
本文介绍了名称为“CON”不存在于当前上下文存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用LINQ语句做一团。我得到一个错误的名称'骗子'没有在目前的情况下存在。



在我的代码后的选择,我试图让 ActivityID 价值,但名单'骗子'不可用

 列表<贡献>捐款= 
contLogic.GetAllContibutionsByActivityIDToList(ActivityID);

组VAR =从捐款
组CON CON通过con.Response
到gResponse
选择新的
{
GROP = gResponse。 COUNT(),
con.ActivityID
};



我看看微软的样品,我不知道我做错了什么。



微软示例:

 列表<产品与GT;产品= GetProductList(); 

变种orderGroups从PROD =产品中
组督促由prod.Category到prodGroup
选择新{类别= prodGroup.Key,产品= prodGroup};

ObjectDumper.Write(orderGroups,1);


解决方案

CON 是不是在您的分组范围。请注意,在微软为例,其原来的查询元素是,但分组后,他们提到了 prodGroup



您查询是基于一个共同的响应,你基本上是丢失的个人元素组合在一起 CON 为更大的整体。您可能需要通过新的拓展您的分组,包括不仅仅是响应更标准,如

 组{con.Response, con.ActivityID} 

,然后通过


$ b指ID $ b

  gResponse.Key.ActivityID 

也许访问也许是的第一个的元素的每个组内ActivityID

  gResponse.First()。ActivityID 

不为你想完成什么更多的信息,我不能给你需要如何进行具体咨询。


I'm trying to make a group by statement using LINQ. I am getting an error The name 'con' does not exist in the current context.

In my code after the select, I trying to get the ActivityID value but the list 'con' unavailable.

List<Contribution> contributions =
    contLogic.GetAllContibutionsByActivityIDToList(ActivityID);

var groups = from con in contributions
             group con by con.Response
             into gResponse
             select new
             {
                grop = gResponse.Count(),
                con.ActivityID
             };

I have look at Microsoft samples, and I don't know what I did wrong.

Microsoft sample:

List<Product> products = GetProductList();

var orderGroups = from prod in products
                  group prod by prod.Category into prodGroup
                  select new { Category = prodGroup.Key, Products = prodGroup };

ObjectDumper.Write(orderGroups, 1);

解决方案

con isn't in scope in your grouping. Note that in the Microsoft example, their original query element was prod, but after the grouping, they referred to prodGroup.

Your query is grouping the elements together based upon a common Response, you are essentially "losing" the individual con for the greater whole. You may need to expand your grouping to include more criteria than just the Response, such as

group by new { con.Response, con.ActivityID }

and then refer to the ID via

gResponse.Key.ActivityID

Or perhaps access perhaps the first element's ActivityID inside each group

gResponse.First().ActivityID

Without more information as to what you are trying to accomplish, I cannot give specific advice for how you need to proceed.

这篇关于名称为“CON”不存在于当前上下文存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆