Not sure how to describe this question.
Here is the example:
I have an entity as Tour. Tour table contains static 3 rows(can be more in the future).
public class Tour
{
public int Id { get; set; }
public string Name { get; set; }
public string Location { get; set; }
}
Each user can turn this options keys.
So I have another table called UserTourSetting to store user options.
public class UserTourSetting
{
public int Id { get; set; }
public int UserId { get; set; }
public int TourId { get; set; }
public bool Enabled { get; set; }
public ApplicationUser User { get; set; }
public Tour Tour { get; set; }
}
When the user loads the page it should always see 3 rows with the status on or off.
When I load UserTourSetting table I get no results as there is no record yet on the table for the user first time. I guess I need to do join with Tour table and also include Tour results as I will need the titles.
When the switches are turned on off then individually it will add a new record if not exists or change Enabled key if exists.
What would be the best way to implement this with EF? I struggle the generate linq statement to load the join table.
here is the method I tried:
public IEnumerable<UserTourSetting> GetUserTourSettings(int userId)
{
var q = from tour in DbContext.Tours
join uts in DbContext.UserTourSettings
on tour.Id equals uts.TourId
where uts.UserId == userId
select uts;
return q;
}
But it does not work. And I cannot access Tour names. Where the include can go in this query?
Thanks,