So what I'm trying to do is create a basic sync system between a CSV and a Database (not using SSIS), it also does some other magic stuff for computations and such like.
The first step of a sync is to remove any users in the DB who are no longer in the CSV file.
I have a List<StaffInfo>
where StaffInfo
is
public class StaffInfo
{
public int ID {get;set;}
public string Firstname {get;set;
// etc etc etc ... ... ...
}
My initial thoughts was to get a list of UserIDs from the list then select users not in the DB and then loop through and delete, but this seems very wasteful
// oUsers contains List<StaffInfo>
// Context is the reference to the EF Context
var myList = (from c in oUsers select c.ID).ToList();
var usersNotInDb = context.Users.Where(x => !myList.Contains(x.UserId));
foreach (var user in usersNotInDb)
{
context.DeleteObject(user);
}
context.SaveChanges();
Is there a better way to accomplish this without so much either data transfer or manipulation of data directly (i.e converting the complex object to a list of user ids)