我有下面的代码应该将所选数据返回到我的视图,但是我遇到了来自reas.CarType的重复问题...
这是一段代码:
public JsonResult GetRegister()
{
using (FamilyRegisterContext db = new FamilyRegisterContext())
{
var familyRegistarData = (from fag in db.FamiliyGroups
from reas in db.CarsAndRealEstate
where (fag.GroupedFamilyId == reas.GroupedFamilyId)
select new
{
fag.FamilyGroupid,
fag.FamilyName,
fag.FamilyMemberName,
fag.Year,
fag.BankName,
fag.Amount,
reas.CarType,
reas.ProductionYear,
reas.RegistrationNumber,
reas.Address,
reas.Other
}).ToList().Distinct();
var distinct = familyRegistarData.GroupBy(s => s.FamilyMemberName).Select(y => y.First());
return new JsonResult { Data = distinct, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
}[enter image description here][1]
在我添加GroupBy之前,我遇到了与FamilyMemberName相同的问题,但现在已经解决了..我现在唯一的问题是来自CarType的重复...
请帮助我卡住:)
"更新与#34;
This is my angular view presentation
[2]: http://i.stack.imgur.com/juCwZ.png
这是一种表关系 http://tinypic.com/view.php?pic=35ch4t2&s=9#.Vo6pX4bR9aQ
这是我表格中的数据 http://tinypic.com/view.php?pic=2ev6xzb&s=9#.Vo6s44bR9aQ
正如我所看到的那样,CarType和地址是重复的......
答案 0 :(得分:0)
我认为以下代码应该做你想要实现的目标:
var distinct = familyRegistarData
.GroupBy(s => new { s.FamilyMemberName, s.CarType })
.Select(y => y.First());