3
还有就是我的分贝的简化模型:实体框架的核心:与问题包含方法
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
{...}
所以,在控制器的I类试图让聊天内容,如包含当前用户作为参与者:
var user = GetUser();
_context.Chats.Where(chat => chat.Users.Contains(user)).ToList();
此代码抛出异常:
不能使用表达式的类型...... ApplicationUser为 参数” S型 方法的 “Microsoft.EntityFrameworkCore.Storage.ValueBuffer”“布尔 包含[ValueBuffer](System.Collections.Generic.IEnumerable`1 [Microsoft.EntityFrameworkCore.Storage.ValueBuffer], Microsoft.EntityFrameworkCore.Storage.ValueBuffer) “
这里有什么问题?
请提供您的控制器代码多一点信息。你想把它分配给什么? –
实际的问题是你试图比较对象('用户')作为一个洞。由于EF在后台转换为SQL,这将失败。没有用于比较对象的SQL函数。最好你通过主键进行查找。 – Thor