Linq 分组或者去重

残月照我心 2012-11-13 05:25:35
   public List<fuction> Getlist(string School)
{
Db_Jst_ChatgroupDataContext S_Info = new Db_Jst_ChatgroupDataContext();
IQueryable<fuction> item = from G_info in S_Info.Group_Info1
from G_School in S_Info.Group_SchoolInfo
where G_info.Gschool.Equals(School)
select new fuction
{
省份 = G_info.Gprovince,
学校 = G_info.Gschool,
班级 = G_info.GroupName,
联系人 = G_School.Contact,
联系邮箱 = G_School.Email,
联系电话 = G_School.Tel
};
return item.ToList();
}
...全文
375 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
残月照我心 2012-11-14
  • 打赏
  • 举报
回复
求来人...
残月照我心 2012-11-14
  • 打赏
  • 举报
回复
引用 7 楼 Microogle2012 的回复:
public List<fuction> Getlist(string School) { Db_Jst_ChatgroupDataContext S_Info = new Db_Jst_ChatgroupDataContext(); IQueryable<fuction> item = from G_info i……
请教下,分组应该写在哪里?用G_School.Contact来分组应该怎么写
残月照我心 2012-11-14
  • 打赏
  • 举报
回复
引用 5 楼 q107770540 的回复:
本帖最后由 q107770540 于 2012-11-13 17:51:11 编辑 C# code? 12345678910111213 public class FuctionComparer : IEqualityComparer<fuction> { public bool Equals(fuction f1, fuction f……
帮我改下我的啊,接触Linq时间不长,看不懂
天言午冉 2012-11-14
  • 打赏
  • 举报
回复
public List<fuction> Getlist(string School) { Db_Jst_ChatgroupDataContext S_Info = new Db_Jst_ChatgroupDataContext(); IQueryable<fuction> item = from G_info in S_Info.Group_Info1 from G_School in S_Info.Group_SchoolInfo where G_info.Gschool.Equals(School) select new fuction { 省份 = G_info.Gprovince, 学校 = G_info.Gschool, 班级 = G_info.GroupName, 联系人 = G_School.Contact, 联系邮箱 = G_School.Email, 联系电话 = G_School.Tel }; return item.Distinct().ToList(); }
残月照我心 2012-11-14
  • 打赏
  • 举报
回复
[quote=引用 5 楼 q107770540 的回复:] return item.ToList().Distinct(new FuctionComparer ());//? [quote] 我的应该怎样写哦, return item.ToList().Distinct(new fuction());这样写不对哦
q107770540 2012-11-13
  • 打赏
  • 举报
回复
public class FuctionComparer : IEqualityComparer<fuction>  
{
public bool Equals(fuction f1, fuction f2)
{
return (f1.省份 == f2.省份 && f1.学校 == f2.学校);
}
public int GetHashCode(fuction t)
{
return t.ToString().GetHashCode();
}
}

return item.ToList().Distinct(new FuctionComparer ());
q107770540 2012-11-13
  • 打赏
  • 举报
回复
参考: http://blog.csdn.net/q107770540/article/details/5784646
残月照我心 2012-11-13
  • 打赏
  • 举报
回复
引用 2 楼 bdmh 的回复:
linq有distinct函数
我的应该加在哪里?
bdmh 2012-11-13
  • 打赏
  • 举报
回复
linq有distinct函数
残月照我心 2012-11-13
  • 打赏
  • 举报
回复
上面查询出来为什么会出现重复的行,求解. 如果消除重复行,代码应该怎么改. 如果利用分组来消除重复,分组的格式是怎么样的

8,497

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧