过滤一列数据的重复项,但显示另一列的所有数据
我正在做 mvc3 和 linQ 我有这样的数据库,
class student gender
A john Male
B George Male
A bill Female
A Steve Male
我该如何编码来过滤重复项,结果如下
A
John male
bill female
steve male
B
George male
我尝试了方法A
var bb = from bbb in unitOfWork.Checklists
orderby bbb.class
select bbb;
和方法B
var group = (from p in unitOfWork.Checklists
group p by p.class into g
select new Checklists
{
class= g.Key,
name= g.ToString()
}).AsEnumerable();
,但都失败了~ 有什么想法吗?这让我很头疼!
i am doing mvc3 and linQ
i have the database like this
class student gender
A john Male
B George Male
A bill Female
A Steve Male
how do i code to filter the duplicate as the result as below
A
John male
bill female
steve male
B
George male
i have tried method A
var bb = from bbb in unitOfWork.Checklists
orderby bbb.class
select bbb;
and also method B
var group = (from p in unitOfWork.Checklists
group p by p.class into g
select new Checklists
{
class= g.Key,
name= g.ToString()
}).AsEnumerable();
but all failed~
Any idea for this ? This is breaking my head!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在 Visual Studio C# 示例中使用 ObjectDumper 项目
输出是
示例 MVC 代码
在您的控制器中
在您的视图中
try to use ObjectDumper project in the visual studio C# sample
The output is
Example MVC code
In your controller
In your view
class 是 C# 中的关键字,不能用作属性名称。您需要一个分组依据,并且可能需要创建一个包装类来传递结果
class is a keyword in C# and I you can't use as property names. You need a group by and probably you need either to create a wrapper class to pass the result