我試圖設置一個方法,返回與您已註冊的演示文稿不重疊的所有演示文稿。然而,當試圖實現這個時,我遇到了一個我似乎無法修復的錯誤,我環顧四周,無法找到任何類似的問題。我錯過了明顯的東西嗎?實體框架核心:InvalidOperationException
這是錯誤:
InvalidOperationException: variable 't0' of type 'Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier`2[NameSpace.Models.Presentation,Microsoft.EntityFrameworkCore.Storage.ValueBuffer]' referenced from scope '', but it is not defined
這是我的模型。
public class ApplicationUser : IdentityUser
{
public List<Presentation> MyPresentations { get; set; }
public List<PresentationUser> RegisteredPresentations { get; set; }
}
public class Presentation
{
public int PresentationId { get; set; }
public string HostId { get; set; }
public ApplicationUser Host { get; set; }
public List<PresentationUser> Attendees { get; set; }
public int TimeId { get; set; }
public PresentationTime Time { get; set; }
}
public class PresentationUser
{
public int PresentationId { get; set; }
public Presentation Presentation { get; set; }
public string ApplicationUserId { get; set; }
public ApplicationUser ApplicationUser { get; set; }
}
public class PresentationTime
{
public int PresentationTimeId { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
}
這是我不能去上班
private async Task<IQueryable<Presentation>> GetAvailablePresentations()
{
User user = await context.Users
.Include(u => u.RegisteredPresentations)
.ThenInclude(eu => eu.Presentation.Host)
.FirstOrDefaultAsync(u => u.Id == userManager.GetUserId(User));
var Presentations = context.Presentations
.Include(e => e.Host)
.Include(e => e.Time)
.Include(e => e.Attendees)
.ThenInclude(e => e.ApplicationUser)
// Filter Out Conditions
.Where(e => e.Attendees.All(u => u.ApplicationUserId != user.Id)) // Cannot see Presentations they are attending.
.Where(e => e.HostId != user.Id); // Cannot see their own Presentation
var debug = user.RegisteredPresentations.Select(ex => ex.Presentation).ToList();
// This section makes it so that users can't sign up for more that one Presentation per timeslot.
// Error Occurs Here
Presentations = Presentations.Where(e => debug.All(ex =>
ex.Time.EndTime < e.Time.StartTime || e.Time.EndTime < ex.Time.StartTime));
// This also does not work
// Presentations = Presentations.Where(e => debug.All(ex => ex.Time.StartTime != e.Time.StartTime));
return Presentations;
}
如果有人能幫助我解決這個問題它會帶來巨大幫助的方法。
注:我剝離了很多其他邏輯來幫助隔離此問題,因此我可能在此代碼中有幾個不必要的.Include()
。
完美的解釋,謝謝。 –