score:1

Accepted answer

yes, there are a few approaches you can take depending on taste. the easiest way to simplify what you've got would be this:

var branchtoremove = _libraryservice.getlibrary(id);
// .single() will throw an exception unless there is one and only one match.
var consortremove = userconsortia.single(
    c => c.branches.any(
        b => string.equals(b.libraryid, id, stringcomparison.ordinalignorecase));
// remove the consortia
userconsortia.remove(consortremove);

score:1

why not something like this? it looks to me from your code that you want to remove the targeted "removal branch" from all consortiums in you collection.

foreach (userconsortium userconsortium in userconsortia)
{
    userconsortium.branches.removeall(c => string.equals(c.libraryid, id, stringcomparison.ordinalignorecase));
}

Related Query

More Query from same tag