Get a list of elements by their ID in entity framework

前端 未结 3 1667
花落未央
花落未央 2021-02-05 00:49

How can I get all elements that are in another list by ID? For eg; I have List roles; I\'d like to get all roles from the database that are in this this list by their Id.

<
3条回答
  •  星月不相逢
    2021-02-05 01:21

    var listOfRoleId = user.Roles.Select(r => r.RoleId);
    var roles = db.Roles.Where(r => listOfRoleId.Contains(r.RoleId));
    

提交回复
热议问题