Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();
Posted
Updated 27-Sep-18 16:00pm
Comments
pankajupadhyay29 27-Sep-18 13:36pm    
Try to get the DB query using profiler and see if it is returning duplicate records. Seeing this indicates there is a one to many relationship which is returning multiple records.
Zain Nabi 27-Sep-18 13:52pm    
How do I get DB query..
Maciej Los 27-Sep-18 14:22pm    
You can use LinqPad ;)
[no name] 27-Sep-18 17:51pm    
Why are you joining twice on "SpouseDetails"? Are these bigamists?
Zain Nabi 28-Sep-18 1:47am    
Greetings I have removed one spouseDetails from the join but the query still throws duplicates

1 solution

 
Share this answer
 
v2
Comments
ZainNabi 5-Oct-18 9:13am    
The distinct does not work because there are not duplicate values in my database. Also I don't want to group because each value is unuqie

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900