C'è il mio modello semplificato di 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
{...}
Quindi, nella classe controller, cerco di ottenere chat come contenere l'utente corrente come partecipante:
var user = GetUser();
_context.Chats.Where(chat => chat.Users.Contains(user)).ToList();
Questo codice genera un'eccezione:
Non è possibile utilizzare il tipo di espressione ... ApplicationUser per il tipo di parametro "Microsoft.EntityFrameworkCore.Storage.ValueBuffer" del metodo "Boolean Contains [ValueBuffer] (System.Collections.Generic.IEnumerable`1 [Microsoft.EntityFrameworkCore.Storage.ValueBuffer ], Microsoft.EntityFrameworkCore.Storage.ValueBuffer) "
Qual è il problema qui?
Hai bisogno di usare Any (), come questo
var chatsList =_context.Chats.Where(chat => chat.Users.Any(u => u.id== user.id)).ToList();