class Model
{
public string col {get;set;}
public string co2 {get;set;}
public string co3 {get;set;}
public string co4 {get;set;}
}
var result = new list<Model>{new Model { col1 = "1",col2 = "True",col3 = "True",col4 = "True"}
,
new Model { col1 = "2",col2 = "True",col3 = "False",col4 = "True"}
,
new Model { col1 = "2",col2 = "True",col3 = "False",col4 = "False"}
};对   result  后3列进行group by  True算1其余算2  不考虑异常情况 谢谢了  
分不多  请见谅  

解决方案 »

  1.   

    var result = sourcelist
                 .Select(x => new Model() 
                     { 
                        col1 = (x.col2 == "True" && x.col3 == "True" == x.col4 == "True") ? "1" : "2",
                        col2 = x.col2,
                        col3 = x.col3,
                        col4 = x.col4
                     });
      

  2.   


    void Main()
    {
    var result = new List<Model>{
    new Model { col1 = "1",col2 = "True",col3 = "True",col4 = "True"},
    new Model { col1 = "2",col2 = "True",col3 = "False",col4 = "True"},
    new Model { col1 = "2",col2 = "True",col3 = "False",col4 = "False"}
    };
    var query=result.GroupBy(r=>new {r.col2,r.col3,r.col4})
    .Select(g=>new Model{ 
    col1=g.FirstOrDefault().col1,
    col2=g.Key.col2=="True"?"1":"2",
    col3=g.Key.col3=="True"?"1":"2",
    col4=g.Key.col4=="True"?"1":"2"
    });
    Console.WriteLine(query);
    }class Model
    {
    public string col1 {get;set;}
    public string col2 {get;set;}
    public string col3 {get;set;}
    public string col4 {get;set;}
    }
      

  3.   

    对result中的 MODEL的后3列    进行 GROUP BY 操作  var q = from p in  result  group by col2,clo3,clo4
      

  4.   

    本帖最后由 caozhy 于 2012-02-08 10:18:08 编辑
      

  5.   

    我也很诧异  一个GROUP BY而已  能让这么多位 星星  理解不了