简体   繁体   English

如何从表格中仅获得一列?

[英]How can I get just one column from a table?

i have a table named "table_1" which contains id, col_1, col_2, col_3. 我有一个名为“ table_1”的表,其中包含id,col_1,col_2,col_3。 col_1 is the summary property, so, when i query "table_1" (by any filter), i get the query result summarized by the summary property "col_1". col_1是摘要属性,因此,当我查询“ table_1”(通过任何过滤器)时,我将获得由摘要属性“ col_1”汇总的查询结果。

I need to get the same result but summarized by "col_2" that isn't the summary property. 我需要得到相同的结果,但用不是摘要属性的“ col_2”进行汇总。 Can anyone help me? 谁能帮我?

Here's my query code: 这是我的查询代码:

partial void table_1_PreprocessQuery(ref IQueryable<table_1Item> query)
{
    query = (from item in query
    select item.col_2).Execute().Distinct();
}

It doesn't work because it throw me an exception like this: 它不起作用,因为它引发了如下异常:

"Cannot implicitly convert type 'System.Linq.IQueryable in System.Linq.IQueryable" “无法在System.Linq.IQueryable中隐式转换类型'System.Linq.IQueryable”

col_2 is a string type. col_2是字符串类型。 So i need that the query result type is System.Linq.IQueryable<table_1Item> . 所以我需要查询结果类型是System.Linq.IQueryable<table_1Item>

change 更改

partial void table_1_PreprocessQuery(ref IQueryable<table_1Item> query)
    {
        query = (from item in query
                 select item.col_2).Execute().Distinct();
    }

to

partial void table_1_PreprocessQuery(ref IQueryable<table_1Item> query)
    {
        query = (IQueryable<table_1Item>)(from item in query
                 select item.col_2).Execute().Distinct();
    }

This will cast explicitly. 这将显式转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM