I need to use equal instead of Contains. I have an array of codes called selectedDeviceTypeIDs i assume it has two codes {1,2}
I need get result from the query if Devices ids are exactly {1,2} so i have replace selectedDeviceTypeIDs.Contains with selectedDeviceTypeIDs.equal or something like that ...
m => m.Devices.Any(w => selectedDeviceTypeIDs.Contains(w.DeviceTypeID)
if (DeviceTypeIDs != null)
{
Guid[] selectedDeviceTypeIDs = DeviceTypeIDs.Split(',').Select(Guid.Parse).ToArray();
query = query.Where(j => j.HospitalDepartments.Any(jj => jj.Units.Any(m => m.Devices.Any(w => selectedDeviceTypeIDs.Contains(w.DeviceTypeID)))));
}
You need to check if the
selectedDeviceTypeIDs
contains every device, and that every device containsselectedDeviceTypeIDs
. You could use this:Option 1:
If you care about the Order of the items, use
SequenceEqual
extension method. This will return false, even if the collection has the items but in different orderOption 2:
If you don't care about the order , use
All
extension method. This will return true, if the items in both collections are same irrespective of the order.Use !.Except().Any() to make sure m.Devices doesn't contains any DeviceTypeID not present in selectedDeviceTypeIDs