find not exist item in to list A and aexist in list B in ef core

asp.net c# entity-framework entity-framework-core

Question

i have to list and in to list i have list of string :

 public async Task<OperationResult<string>> SetAccess(AccessLevelDto accessLevels)
    {
            var access = await GetAccessLevels(accessLevels.RoleId);
    }

 private async Task<IEnumerable<string>> GetAccessLevels(Guid roleId)
    {
        return await AccessLevels.Where(x => x.RoleId == roleId).Select(x => x.Access).ToListAsync();
    }

one list : GetAccessLevels(accessLevels.RoleId) and second accessLevels.Access

i want to find with items exist in list A and not exist in list B then put then in the var mustremove .

how can i do this ????

1
0
4/17/2020 4:20:18 PM

Popular Answer

Use "Not Contains" LINQ expression:

var listA = new List<string> { "One", "Two", "Three" };
var listB = new List<string> { "One", "Three" };

var mustremove = listA.Where(x => !listB.Contains(x));

mustremove will contain one element: "Two"

0
4/17/2020 7:56:16 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow