Asp.net 实体框架核心:Contains方法的问题

Asp.net 实体框架核心:Contains方法的问题,asp.net,asp.net-core,entity-framework-core,Asp.net,Asp.net Core,Entity Framework Core,下面是我的db简化模型: public class Chat { public ICollection<ApplicationUser> Users {get; set;} //nav property - represents participants of a chat } public class ApplicationUser : IdentityUser // it represents a net-identity user; it does not have any

下面是我的db简化模型:

public class Chat
{
public ICollection<ApplicationUser> Users {get; set;} //nav property - represents participants of a chat
}

public class ApplicationUser : IdentityUser // it represents a net-identity user; it does not have any references to chats
{...}
此代码引发异常:

您不能将表达式…ApplicationUser的类型用于 参数类型 方法“Boolean”的“Microsoft.EntityFrameworkCore.Storage.ValueBuffer” 包含[ValueBuffer](System.Collections.Generic.IEnumerable`1[Microsoft.EntityFrameworkCore.Storage.ValueBuffer], Microsoft.EntityFrameworkCore.Storage.ValueBuffer)”

这里有什么问题

您需要像这样使用Any()

 var chatsList =_context.Chats.Where(chat => chat.Users.Any(u => u.id== user.id)).ToList();

请提供更多关于控制器代码的信息。您试图将其分配给什么?实际问题是,您试图将对象(“用户”)作为孔进行比较。由于EF在后台转换为SQL,因此将失败。没有用于比较对象的SQL函数。最好按主键查找。
 var chatsList =_context.Chats.Where(chat => chat.Users.Any(u => u.id== user.id)).ToList();