How can I solve this problem ?
I need to do this check between the database and a list of in-memory objects
var contactIds = db.AGN_RestrictionContact_Involvement_PositionLinked
.Where(x => x.Id_AGN_Contato == formModel.ContactId);
var positionRemove = contactIds.Where(x => !formModel.PositionsInvolvement
.Any(l => l.Id == x.Id_PRO_PosicaoEnvolvido)).ToList();
foreach (var position in positionRemove)
{
db.AGN_RestrictionContact_Involvement_PositionLinked.Remove(position);
}
CodePudding user response:
I managed to reach a simple resolution where I add to the end of this query =>
var contactIds = db.AGN_RestrictionContact_Involvement_PositionLinked
.Where(x => x.Id_AGN_Contato == formModel.ContactId).ToList();
the ToList()
Where the query will also stay in memory so as not to cause problems in my viewModel's 'PositionsInvolvement' property