I have table named PickupLocations in my db that has columns externalID and Status. I get from an api a list of LockerIDs.
What I would like to do is to change the status of the rows who are not received from the api to 0.
E.g:
In this scenario, only "456" wasn't received from the api therefore it status should be updated to 0.
DataBase:PickupLocations API
_________________ LockerID
|ExternalID| Status| |"789"|
--------------------| |"AA1"|
| "123" | 1 | |"123"|
| "456" | 1 | |"665"|
| "789" | 1 | |"555"|
If this was SQL I would do something like this:
Update PickupLocations set status = 0
where ExternalID in
(
select pl.ExternalID
from pickuplocations pl left join LockerIDs l on pl.ExternalID = l.LockerID
where l.LockerID is null
)
I am trying to achieve this SQL update in code, but with no success:
List<LockerList> activeLockers = results.LockerList;
using (var dbc = new MyDBContext())
{
//First attemp
dbc.PickupLocations.Where(pl => !activeLockers.Select(x => x.LockerId).Any(l => l.Contains(pl.ExternalID))).ToList().ForEach(x => x.Status = 0);
//Second attemp
dbc.PickupLocations.Where(pl => !activeLockers.Any(l => l.LockerId == pl.ExternalID))
.ToList()
.ForEach(x => x.Status = 0);
dbc.SaveChanges();
}
Error for both attempts:
Unable to create a constant value of type 'BoxitObjects.LockerList'. Only primitive types or enumeration types are supported in this context.