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 3941074
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:29:48+00:00 2026-05-20T00:29:48+00:00

New to Linq to Entities. I am using entity framework and linq. In my

  • 0

New to Linq to Entities. I am using entity framework and linq. In my db I have something akin to Cars, Users, UserCars where UserCars holds the ID from User and Cars. Standard stuff.

EF maps this to Car and User objects.

Now a user currently has many cars. Through my application I end up with a new List of Car IDs.

I need to update the UserCars table with the new list of cars for the current user.

So what needs to happen basically, The current cars for the user are deleted, and the new list of car ids/userid is inserted.

What is the easiest way to go about this using linq to entities?

  • 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-20T00:29:49+00:00Added an answer on May 20, 2026 at 12:29 am

    The User entity should have a Cars property. You can just clear that collection and then add the new Cars to reflect the new state, i.e. somewhat like this:

    User myUser = context.Users.First();
    var carCollection = context.Cars.Where( c => carIdCollection.Contains(c.Id));
    myUser.Cars.Clear();
    
    foreach(Car car in carCollection)
       myUser.Cars.Add(car);
    
    ...
    context.SaveChanges();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The goal: I'm trying to use the new Entity Framework 4.1 DbContext API (using
I am unable to update the record in SharePoint 2010 using new linq feature.
I am using the following code to update an entity. Service.Update(_policy); where policy is
When I execute the code below I receive the error message: LINQ to Entities
When you are writing a linq query that involves two tables/entities for which you
I have a DataList which is bound to a SqlDataSource, Ive got a LINQ
Kind of new to linq, whats the simplest way to retrieve a single result
I'm new to LINQ and am finding it a bit difficult with understanding some
I have this situation: My ModelView: public class Subject { public int ID {
Mjello there! I'm at the moment trying to create a F# application, and now

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.