Comment puis-je Sélectionner tous les amis de l'utilisateur actuellement connecté et les Chats Privés (Id Chat) entre l'utilisateur et de ses amis? Je suis en mesure d'obtenir les amis de l'utilisateur, mais j'ai du mal également à obtenir le Chat entre eux.
// Select all the User's friends and the chat (Id) between them
var friends = await _context.Friendships // Get the Friendships
.Include(x => x.Friend).ThenInclude(x => x.ChatUsers).ThenInclude(x => x.Chat)
.Where(x => x.Status == StatusCode.Accepted && x.ApplicationUserId == userId)
.Select(x => x.Friend)
.ToListAsync();
L'amitié table
public class Friendship
{
// The primary keys/foreign keys of the associated tables
public string ApplicationUserId { get; set; }
public string ApplicationFriendUserId { get; set; }
// Reference to the user that has the friend
public User ApplicationUser { get; set; }
// Reference to the friend
public User Friend { get; set; }
// The status of the friendship
public StatusCode Status { get; set; }
}
Table utilisateur
public class User : IdentityUser
{
// Reference to all user's chats
public ICollection<ChatUser> ChatUsers { get; set; }
// Reference to all the user's friendships
public ICollection<Friendship> UsersFriendships { get; set; }
// Reference to all the friend's friendships (their point of view)
public ICollection<Friendship> FriendsFriendships { get; set; }
}
ChatUser table
public class ChatUser
{
// The primary key/foreign keys of the associated tables
public int ChatId { get; set; }
public string UserId { get; set; }
// The role that the User can be
public UserRole Role { get; set; }
// Reference to the chat
public Chat Chat { get; set; }
// Reference to the user
public User User { get; set; }
}
Chat
public class Chat
{
// The primary key
public int Id { get; set; }
// The chat's name
public string Name { get; set; }
// The chat type, e.g room, private
public ChatType Type { get; set; }
// Reference to all the Chat's Users
public ICollection<ChatUser> ChatUsers { get; set; }
}
Merci