[英]How can I get just one column from a table?
我有一个名为“ table_1”的表,其中包含id,col_1,col_2,col_3。 col_1是摘要属性,因此,当我查询“ table_1”(通过任何过滤器)时,我将获得由摘要属性“ col_1”汇总的查询结果。
我需要得到相同的结果,但用不是摘要属性的“ col_2”进行汇总。 谁能帮我?
这是我的查询代码:
partial void table_1_PreprocessQuery(ref IQueryable<table_1Item> query)
{
query = (from item in query
select item.col_2).Execute().Distinct();
}
它不起作用,因为它引发了如下异常:
“无法在System.Linq.IQueryable中隐式转换类型'System.Linq.IQueryable”
col_2
是字符串类型。 所以我需要查询结果类型是System.Linq.IQueryable<table_1Item>
。
更改
partial void table_1_PreprocessQuery(ref IQueryable<table_1Item> query)
{
query = (from item in query
select item.col_2).Execute().Distinct();
}
至
partial void table_1_PreprocessQuery(ref IQueryable<table_1Item> query)
{
query = (IQueryable<table_1Item>)(from item in query
select item.col_2).Execute().Distinct();
}
这将显式转换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.