使用Linq的不同行(Distinct rows using Linq)
我一直试图让这个查询长期工作!
表:
ID - 基础 - 日期
1 - 1991 - 2013-09-13
2 - 1992 - 2013-01-12
3 - 1990 - 2013-09-13
4 - 1998 - 2013-02-11我想获得具有不同日期的所有行。 例如:
要求的输出
ID - 基础 - 日期
1 - 1991 - 2013-09-13
2 - 1992 - 2013-01-12
4 - 1998 - 2013-02-11我到目前为止所显示的所有记录都不是我想要的。
我的代码:public IEnumerable<tableName> GetAllRecords() { var records = _tableName.GetAll().GroupBy(tb => tb.Date).SelectMany(tb => tb.Distinct()); return records; }
如何获得所需的输出?
I have been trying to get this query to work from a long time!
Table:
ID - Base - Date
1 - 1991 - 2013-09-13
2 - 1992 - 2013-01-12
3 - 1990 - 2013-09-13
4 - 1998 - 2013-02-11I want to get all the rows with distinct Dates. For eg:
Required Output
ID - Base - Date
1 - 1991 - 2013-09-13
2 - 1992 - 2013-01-12
4 - 1998 - 2013-02-11What i have so far is displaying all the records and thats not what I want.
My Code:public IEnumerable<tableName> GetAllRecords() { var records = _tableName.GetAll().GroupBy(tb => tb.Date).SelectMany(tb => tb.Distinct()); return records; }
How do I get the required output?
原文:https://stackoverflow.com/questions/18950724