Я пытаюсь преобразовать инструкцию SQL в LINQ.
У меня есть следующие модели:
public class GamesNight
{
public int id { get; set; }
[DisplayName("Games Night Official Name")]
public string EventName { get; set; }
[DisplayName("Description")]
public string EventDescription { get; set; }
[DisplayName("Date and Time")]
[DataType(DataType.Date)]
public DateTime DateTime { get; set; }
public virtual ApplicationUser User { get; set; }
public bool Active { get; set; }
}
и GamesNightAttendance, это более или менее связывает пользователя с событием ночной игры.
public class GamesNightAttendance
{
[Key]
public int id { get; set; }
public virtual GamesNight GameNight { get; set; }
public virtual ApplicationUser UserName { get; set; }
public bool Attendance { get; set; }
}
, поэтому пользовательорганизует GamesNight, тогда другие пользователи смогут посещать ночные игры с помощью gamesnightattendancemodel.
У меня есть запрос:
var userID = User.Identity.GetUserId();
var user = db.Users.First(x => x.Id == userID);
var result = from GNS in db.GamesNights
join GNA in db.GamesNightAttendance on GNS.id equals GNA.id
where GNS.Active & GNA.UserName == user
select new UpcomingGNAttendanceViewModel { GamesNight = GNS, Attendance = GNA.Attendance};
Я получаю исключение:
Message = "Невозможно создать постоянное значение типа 'GNR.Models.ApplicationUser'. В этом контексте поддерживаются только примитивные типы или типы перечисления."