Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7066163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:03:04+00:00 2026-05-28T05:03:04+00:00

Here is a very basic example of what I want to do. The code

  • 0

Here is a very basic example of what I want to do. The code I have come up with seems quite verbose… ie looping through the collection, etc.

I am using a Telerik MVC grid that posts back a collection of deleted, inserted and updated ViewModels. The view models are similar but not exactly the same as the entity.

For example… I have:

Order.Lines. Lines is an entity collection (navigation property) containing OrderDetail records. In the update action of my controller using the I have a List names DeletedLines pulled from the POST data. I also have queried the database and have the Order entity including the Lines collection.

Now I basically want to tell it to delete all the OrderDetails in the Lines EntityCollection.

The way I have done it is something like:

foreach (var line in DeletedLines) {
   db.DeleteObject(Order.Lines.Where(l => l.Key == line.Key).SingleOrDefault())
}

I was hoping there was a way that I could use .Interset() to get a collection of entities to delete and pass that to DeleteObject.. however, DeleteObject seems to only accept a single entity rather than a collection.

Perhaps the above is good enough.. but it seemed like there should be an easier method.

Thanks,
BOb

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:03:05+00:00Added an answer on May 28, 2026 at 5:03 am

    Are the items in DeletedLines attached to the context? If so, what about this?

    foreach (var line in DeletedLines) db.DeleteObject(line);
    

    Response to comment #1

    Ok, I see now. You can make your code a bit shorter, but not much:

    foreach (var line in DeletedLines) {
       db.DeleteObject(Order.Lines.SingleOrDefault(l => l.Key == line.Key))
    }
    

    I’m not sure if DeleteObject will throw an exception when you pass it null. If it does, you may be even better off using Single, as long as you’re sure the item is in there:

    foreach (var line in DeletedLines) {
       db.DeleteObject(Order.Lines.Single(l => l.Key == line.Key))
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a very basic question...quite embarassing, but here goes: I have a Stopwatch
This seems very basic and I must be missing something, but here goes anyways...
Now I must be missing something here, as this seems a very basic issue
Well, I think I have a very basic doubt here: I'm developing an app
Alright, here goes. I'm making a very basic app, and I want the user
I only have very basic knowledge on Javascript and I want to be able
I've got this to work using a very basic example(outlined below) and I want
This could be a very basic question but i want to confirm here. Im
Here is a very basic class for handling sessions on App Engine: Lightweight implementation
This is very basic stuff , but here goes. I find that I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.