Article
ArticleID
ImageMaster
ImageID
ImageType (1, 2, 3, or 4)
ImageArticle <-- this entity is produced by EF because of extra fields
ImageID
ArticleID
Title
Desc
Alt
I'm trying to delete all entries in ImageArticle where ArticleID=### and ImageType=4
I tried
Expand|Select|Wrap|Line Numbers
- foreach (ImageArticle ia in Article.ImageArticles.Where(i => i.ImageMaster.TypeID == 4))
- {
- context.ImageArticles.Delete(ia);
- }
- context.SaveChanges();
I also tried Article.ImageArticles.Remove(ia), but then it wont let me iterate through the loop because the collection changed inside the loop.
The next thing I tried was gathering all the ImageIDs that I need to delete, then do this:
Expand|Select|Wrap|Line Numbers
- context.ExecuteStoreCommand("DELETE FROM ImageArticle WHERE ArticleID = " + Article.ArticleID + " AND ImageID in (" + IDs + ")");
- context.SaveChanges();
How can I achieve deleting these rows in EF?