0

I have the following....

Dim ProjectToDelete As Project2Host = dc.Project2Hosts.Single(Function(p) p.Host = tb_Host.Text)
dc.Projects2Hosts.DeleteOnSubmit(ProjectToDelete)
dc.SubmitChanges

This worked fine as there was only ever one Project associated to a Host.

The rules have now changed and there can be more than one Project per Host. I now need to create a List of ProjectsToDelete and populate that with a Linq query and then do a DeleteAllOnSubmit(ProjectsToDelete).

How do I create the list? I've beem trying .SelectMany but with no joy.

Any help appreciated.

1 Answer 1

2

How about:

For Each item in dc.Project2Hosts.Where(Function(p) p.Host = tb_Host.Text)
    dc.Projects2Hosts.DeleteOnSubmit(item)
Next
dc.SubmitChanges()

OR:

dc.Project2Hosts.DeleteAllOnSubmit(dc.Project2Hosts.Where(Function(p) p.Host = tb_Host.Text))
dc.SubmitChanges()
Sign up to request clarification or add additional context in comments.

4 Comments

Great... I used the second option but corrected it to dc.Project2Hosts.DeleteAllOnSubmit(.....) Thanks... I was getting all mixed up creating a List(Of Project2Host) and then trying to AddRange(myquery)... so simple when you know how. Thanks Ric
Thanks, I forgot to put that in. Updated. Did it work? You could have removed the contents within DeleteOnSubmit(), called .ToList() on it and placed that in there instead, but there's no need.
I have to get used to stop using return when adding comment. Was editing when you posted your last reply. All worked Thanks
No worries, if it was the answer feel free to mark it as so :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.