Entity framework 实体框架核心:InvalidOperationException

Entity framework 实体框架核心:InvalidOperationException,entity-framework,asp.net-core,asp.net-identity,entity-framework-core,Entity Framework,Asp.net Core,Asp.net Identity,Entity Framework Core,我正在尝试设置一个方法,返回与您注册的演示文稿不重叠的所有演示文稿。然而,在尝试实现这一点时,我遇到了一个似乎无法修复的错误,我环顾四周,没有发现任何类似的问题。我错过了什么明显的东西吗 这就是错误: InvalidOperationException:类型为的变量“t0” 'Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier'2[名称空间.模型.演示文稿,Microsoft.Enti

我正在尝试设置一个方法,返回与您注册的演示文稿不重叠的所有演示文稿。然而,在尝试实现这一点时,我遇到了一个似乎无法修复的错误,我环顾四周,没有发现任何类似的问题。我错过了什么明显的东西吗

这就是错误:

InvalidOperationException:类型为的变量“t0” 'Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier'2[名称空间.模型.演示文稿,Microsoft.EntityFrameworkCore.Storage.ValueBuffer]' 从作用域“”引用,但未定义它

这些是我的模型

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; }
}
公共类应用程序用户:IdentityUser
{
公共列表MyPresentations{get;set;}
公共列表RegisteredPresentations{get;set;}
}
公开课演示
{
公共int表示ID{get;set;}
公共字符串HostId{get;set;}
公共应用程序用户主机{get;set;}
公共列表与会者{get;set;}
公共int-TimeId{get;set;}
公共PresentationTime时间{get;set;}
}
公共类演示用户
{
公共int表示ID{get;set;}
公共演示文稿{get;set;}
公共字符串applicationSerID{get;set;}
公共应用程序用户应用程序用户{get;set;}
}
公共类呈现时间
{
public int PresentationTimeId{get;set;}
公共日期时间开始时间{get;set;}
公共日期时间结束时间{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;
}
专用异步任务GetAvailablePresentations()
{
User=wait context.Users
.包括(u=>u.RegisteredPresentations)
.thenclude(eu=>eu.Presentation.Host)
.FirstOrDefaultAsync(u=>u.Id==userManager.GetUserId(用户));
var Presentations=context.Presentations
.Include(e=>e.Host)
.包括(e=>e.Time)
.包括(e=>e.与会者)
。然后包括(e=>e.ApplicationUser)
//过滤条件
.Where(e=>e.attendes.All(u=>u.applicationserid!=user.Id))//无法查看他们正在参加的演示文稿。
.Where(e=>e.HostId!=user.Id);//无法查看他们自己的演示文稿
var debug=user.RegisteredPresentations.Select(ex=>ex.Presentation.ToList();
//本节规定,用户不能在每个时间段注册多个演示文稿。
//这里发生错误
演示文稿=演示文稿。其中(e=>debug.All(ex=>
ex.Time.EndTimedebug.All(ex=>ex.Time.StartTime!=e.Time.StartTime));
返回演示文稿;
}
如果有人能帮我解决这个问题,那将是巨大的帮助


注意:我剥离了许多其他逻辑来帮助隔离此问题,因此我可能在代码中有一些不必要的
.Include()

演示文稿
不是一个列表,它仍然是一个
IQueryable
-一个尚未执行到DB的查询。应用
Where
可以指示EF在SQL中应用额外的
Where
。 但是
debug
是内存中对象的列表(
.ToList()
)。您认为EF将如何将它们传输回DB

如果您希望在DB中应用所有过滤-您应该将
debug
更改为“简单”列表(ID列表?),那么EF将能够将此列表传递回DB

或者,您应该将所有合适的演示文稿读入内存(调用
.ToList()
),并在内存中应用最后一次筛选。您可以从
debug
计算最小值(开始时间)和最大值(结束时间),并将这两个简单值应用于演示文稿查询(您将收到较少的不必要项),然后读取内存并在内存中应用“强”过滤