Reputation: 2201
There is my simplified model of 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
{...}
So, in controller's class I try to get chats such as contain current user as a participant:
var user = GetUser();
_context.Chats.Where(chat => chat.Users.Contains(user)).ToList();
This code throws exception:
You can not use the type of expression ...ApplicationUser for parameter's type "Microsoft.EntityFrameworkCore.Storage.ValueBuffer" of method "Boolean Contains[ValueBuffer](System.Collections.Generic.IEnumerable`1[Microsoft.EntityFrameworkCore.Storage.ValueBuffer], Microsoft.EntityFrameworkCore.Storage.ValueBuffer)"
What is the problem here?
Upvotes: 5
Views: 1925
Reputation: 6203
You need use Any(), like this
var chatsList =_context.Chats.Where(chat => chat.Users.Any(u => u.id== user.id)).ToList();
Upvotes: 6