I have model
public class GrandPrix
{
public int Id { get; set; }
[Required]
[Display(Name = "Имя")]
[DataType(DataType.Text)]
public string Name { get; set; }
public int LocationId { get; set; }
public int? ChampionchipId { get; set; }
public virtual Location Location { get; set; }
public virtual Championchip Championchip { get; set; }
}
public class Location
{
public int Id { get; set; }
[Required]
[Display(Name = "Location")]
[DataType(DataType.Text)]
public string Name { get; set; }
// public virtual ICollection<GrandPrix> GrandPrix { get; set; }
}
I need modify in
ViewBag.LocationId = new SelectList(db.Locations, "Id", "Name");
db.Locations
.Where(l=>l.id is not contained in db.Grandprix.Where(g=>g.ChampionchipId == 1))
this query it work
SELECT Locations.Id as Id, Locations.Name as Name FROM dbo.Locations WHERE Locations.Id Not In (SELECT GrandPrixes.LocationId FROM GrandPrixes WHERE ChampionchipId = 1)
sorry my English and thanks for help.
should give you locations if your FK relationships are set up properly.
Else