【发布时间】:2017-03-24 03:22:57
【问题描述】:
有我的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
{...}
因此,在控制器类中,我尝试获取诸如包含当前用户作为参与者的聊天:
var user = GetUser();
_context.Chats.Where(chat => chat.Users.Contains(user)).ToList();
这段代码抛出异常:
您不能使用 ...ApplicationUser 类型的表达式 参数类型 方法“Boolean”的“Microsoft.EntityFrameworkCore.Storage.ValueBuffer” 包含[ValueBuffer](System.Collections.Generic.IEnumerable`1[Microsoft.EntityFrameworkCore.Storage.ValueBuffer], Microsoft.EntityFrameworkCore.Storage.ValueBuffer)"
这里有什么问题?
【问题讨论】:
-
请提供更多关于您的控制器代码的信息。你想把它分配给什么?
-
实际问题是您试图将对象(“用户”)作为一个洞进行比较。而且由于 EF 在后台转换为 SQL,这将失败。没有用于比较对象的 SQL 函数。最好按主键查找。
标签: asp.net asp.net-core entity-framework-core