按变量区分的通用应用程序对象
Universal app object distinct by variable
我有一个问题:
在我的代码中有这个对象
//:extension for being saved locally
public class FOO
{
public int ID { get; set; }
public string STRINGVALUE{ get; set; }
public int INTVALUE { get; set; }
//ecc..
//SelectAll() method which returns all FOO in local DB
}
现在我想要的是,在某些情况下,选择所有 STRINGVALUE(或 INTVALUE)不重复的 FOO obj。
例如:
List<FOO> fooes = new FOO().SelectAll();
List<FOO> uniqueIntFoo = fooes.distinct(); //here i have to set the clause
Linq 中有 Distinct() 方法,但它比较的是整个项目,而不是它的单个变量。
有人知道我该怎么做吗?
如何对结果进行分组,例如:
通过 Int 和 StrValue:
var uniqueItems = fooes.GroupBy(x => new{x.IntVal, x.StrVal});
按整数计算:
var uniqueItems = fooes.GroupBy(x => x.IntVal);
按照问题作者的建议进行编辑:
fooes.GroupBy(x => x.INTVALUE).Select(y => y.First()).Distinct().ToList();
我有一个问题:
在我的代码中有这个对象
//:extension for being saved locally
public class FOO
{
public int ID { get; set; }
public string STRINGVALUE{ get; set; }
public int INTVALUE { get; set; }
//ecc..
//SelectAll() method which returns all FOO in local DB
}
现在我想要的是,在某些情况下,选择所有 STRINGVALUE(或 INTVALUE)不重复的 FOO obj。
例如:
List<FOO> fooes = new FOO().SelectAll();
List<FOO> uniqueIntFoo = fooes.distinct(); //here i have to set the clause
Linq 中有 Distinct() 方法,但它比较的是整个项目,而不是它的单个变量。
有人知道我该怎么做吗?
如何对结果进行分组,例如: 通过 Int 和 StrValue:
var uniqueItems = fooes.GroupBy(x => new{x.IntVal, x.StrVal});
按整数计算:
var uniqueItems = fooes.GroupBy(x => x.IntVal);
按照问题作者的建议进行编辑:
fooes.GroupBy(x => x.INTVALUE).Select(y => y.First()).Distinct().ToList();