DB Result Set and Model Result Sets Different | Rows Duplicating

Hey Everyone
Just wondering if I can get some help with something. I created an application where people can sign up for a competition. Basically the user can enter their team details, such as Team Name and the Players the are involved.
The application has the ability to view the list of players that have sign up for the competition, where it displays the Team Name and players that are involved.
When I do an SQL Query on the database, the results are fine and shows the correct information. However when I do the same from the app, the rows are for some reason duplicated.
I've attached the images from the db and the application.
DB Result set from: SELECT * FROM [dbo].[CompetitionBookingParticipant_View] WHERE CompetitionId='4b0f9684-1ac6-484a-9fe2-c02ecd098ac2';
View that I receive when asking for the same information.
Query: List<CompetitionBookingParticipant_View> participantsList = await _context.CompetitionBookingParticipant_View.Where(booking => booking.CompetitionId == competition.Id).OrderBy(booking => booking.Division).ThenBy(booking => booking.TeamName).ThenBy(booking => booking.Name).ToListAsync();
Hey @Viorel
Below are the Classes and the SQL View in MSSMS.
public class CompetitionBookingParticipant_View
{
public string Id { get; set; }
public string CompetitionId { get; set; }
public string TeamName { get; set; }
public string Division { get; set; }
public string PrimaryContactName { get; set; }
public string PrimaryContactPhone { get; set; }
public string CompetitionBookingId { get; set; }
public string Name { get; set; }
``string primaryContactName, string primaryContactPhone, string competitionBookingId, string name)
{
Id = id;
CompetitionId = competitionId;
TeamName = teamName;
Division = division;
PrimaryContactName = primaryContactName;
PrimaryContactPhone = primaryContactPhone;
CompetitionBookingId = competitionBookingId;
Name = name;
}
}
Database View
SELECT dbo.CompetitionBooking.Id, dbo.CompetitionBooking.CompetitionId, dbo.CompetitionBooking.TeamName, dbo.CompetitionBooking.Division, dbo.CompetitionBooking.PrimaryContactName,
dbo.CompetitionBooking.PrimaryContactPhone, dbo.CompetitionParticipant.CompetitionBookingId, dbo.CompetitionParticipant.Name
FROM dbo.CompetitionBooking INNER JOIN
dbo.CompetitionParticipant ON dbo.CompetitionBooking.Id = dbo.CompetitionParticipant.CompetitionBookingId
Below is the code I used to grab the information and display it to the view.
.Where(booking => booking.CompetitionId == competition.Id)
.OrderBy(booking => booking.Division)
.ThenBy(booking => booking.TeamName)
.ThenBy(booking => booking.Name)
.ToListAsync();
Try using the Debugger to check the contents of participantsList variable. If it is valid (no duplicates), then maybe it is not correctly displayed. Check the code that displays these results.
Hey Sorry for the delayed response. I ran a print line for each participant, before it gets thrown into the view, and it looks like its the data that its getting is incorrect somehow.
So the view is showing the data correctly, however when the code is asking to get the information, it somehow just creates duplicates.
Team: White Men Can Jump | Division: U14 Boys | Player: Bligh Hall-Leeke
Team: White Men Can Jump | Division: U14 Boys | Player: Bligh Hall-Leeke
Team: White Men Can Jump | Division: U14 Boys | Player: Bligh Hall-Leeke
Team: WMBA | Division: U14 Girls | Player: Alexis Powell
Team: WMBA | Division: U14 Girls | Player: Alexis Powell
Team: WMBA | Division: U14 Girls | Player: Alexis Powell
Team: WMBA | Division: U14 Girls | Player: Alexis Powell
Team: Team name to be confirmed later | Division: U16 Boys | Player: Brendan Cheng
Team: Team name to be confirmed later | Division: U16 Boys | Player: Brendan Cheng
Team: Team name to be confirmed later | Division: U16 Boys | Player: Brendan Cheng
Team: Team name to be confirmed later | Division: U16 Boys | Player: Brendan Cheng
Team: Team name to be confirmed later | Division: U16 Boys | Player: Brendan Cheng
Team: ADRIAN TEST | Division: U23 Boys | Player: TEST BILLY
Team: ADRIAN TEST | Division: U23 Boys | Player: TEST BILLY
Team: ADRIAN TEST | Division: U23 Boys | Player: TEST BILLY
Sign in to comment