Linq重复记录返回 [英] Linq duplicate records returned
本文介绍了Linq重复记录返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据库中没有重复记录,但在我看来。它显示重复。 ClientId是一个Guid,传递给联接中的每个表。
请帮助
< b>我尝试了什么:
I do not have duplicate records in my database however in my view. It shows duplicates. ClientId is a Guid which is passed on to each table in the join.
Please help
What I have tried:
<pre> public ActionResult ClientInfo(string ClientId)
{
var query = (from x in db.FinancialNeedsClients
join y in db.FinancialSpouseDetailss on x.ClientId equals y.ClientId
join z in db.FinancialSpouseDetailss on x.ClientId equals z.ClientId
join c in db.FinancialNeedsChildrens on x.ClientId equals c.ClientId
join d in db.FinancialNeedDependentss on x.ClientId equals d.ClientId
join e in db.FinancialNeedContactDetailss on x.ClientId equals e.ClientId
where x.ClientId == ClientId
select new FinancialNeedClientInfoViewModel()
{
Id = x.Id,
ClientId = x.ClientId,
Surnname = x.Surnname,
FirstName = x.FirstName,
IDNumber = x.IDNumber,
DOB = x.DOB,
Age = (int?)x.Age ?? 0,
Nationality = x.Nationality,
Occupation = x.Occupation,
TaxRef = x.TaxRef,
EmailAddress = x.EmailAddress,
ContactNumber = x.ContactNumber,
MaritaStatus = x.MaritaStatus,
MaritalRegime = x.MaritalRegime,
YearOfMarriage = x.YearOfMarriage,
IfOther = x.IfOther,
SpouseId = (int?)y.Id ?? 0,
SpouseSurnname = y.Surnname,
SpouseFirstName = y.FirstName,
SpouseIDNumber = y.IDNumber,
SpouseDOB = y.DOB,
SpouseAge = (int?)y.Age ?? 0,
SpouseNationality = y.Nationality,
SpouseOccupation = y.Occupation,
SpouseTaxRef = y.TaxRef,
SpouseEmailAddress = y.EmailAddress,
SpouseContactNumber = y.ContactNumber,
ChildId = (int?)c.Id ?? 0,
ChildrenFIrst_Name = c.FIrst_Name,
ChildrenGender = c.Gender,
ChildrenAge = (int?)c.Age ?? 0,
ChildrenOccupation = c.Occupation,
ChildrenDOB = c.DOB,
DepId = (int?)d.Id ?? 0,
DepdendentFIrst_Name = d.FIrst_Name,
DepdendentAge = (int?)d.Age ?? 0,
DepdendentRelationship = d.Relationship,
ContactId = (int?)e.Id ?? 0,
MainMemberResedentialAddress = e.ResedentialAddress,
MainMemberPostalAddress = e.PostalAddress,
MainMemberBusinessAddress = e.BusinessAddress,
MainMemberMobileNumber = e.MobileNumber
}).Distinct().ToList();
推荐答案
c# - linq query从对象列表中返回不同的字段值 - Stack Overflow [ ^ ]
c# - linq distinct并选择新查询 - Stack Overflow [< a href =https://stackoverflow.com/questions/9992117/linq-distinct-and-select-new-querytarget =_ blanktitle =New Window> ^ ]
这篇关于Linq重复记录返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文