from t in a1
from tp in t.a2
group t by t.Name into g
select new { Name = g.Key, cc= g.Count() }
用匿名对象。
public IQueryable<a1> GetxxList()
{
var query = from t in a1
from tp in t.a2
group t by t.Name into g
select new a1{ Name = g.Key, cc= g.Count() }
return query;
}
注意:下面有两种情况,第一种会报“不允许在查询中显式构造实体类型”错误
第一种:
[Table(Name="表名")]
public class a1{
[Column(IsPrimaryKey = true,CanBeNull=false,IsDbGenerated=true,AutoSync=AutoSync.OnInsert)]
public int cc{get;set;}
[Column(Name = "Name")]
public string Name{get;set;}
}
第二种:正确的
public class a1{
public int cc{get;set;}
public string Name{get;set;}
}