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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:39:20+00:00 2026-05-23T14:39:20+00:00

I have an issue about Entity Framework 4 CTP 5, which I realize LINQ

  • 0

I have an issue about Entity Framework 4 CTP 5, which I realize LINQ to SQL handle it better than this, but I insist on using EF 4 because of its Code-First feature.

So here is my problem:

Imagine products with its Tags (or whatever with one to many relation). And tblTags will be changing by deleting some and inserting some tags at a time by user (and user might change them completely different). So in my opinion we can simply delete all old tags and insert new ones (simplest thing to do), although it is a simple idea, LINQ to SQL manage it perfectly amazing unlike EF 4. The codes for comparison with LINQ are:

LINQ to SQL:

Dim oldTags = ctx.Tags.Where(Function(m) m.ProductID = pID)
Dim newTags = 'from user input, like from the model which was posted, like in MVC'

ctx.Tags.DeleteAllOnSubmit(oldTags)
ctx.Tags.InsertAllOnSubmit(newTags)

ctx.SubmitChanges()

EF 4 CTP5:

Dim oldTags = ctx.Tags.Where(Function(m) m.ProductID = pID)
Dim newTags = 'from user input, like from the model which was posted, like in MVC'
For Each item In oldTags
    ctx.Tags.Remove(item)
Next
For Each item In newTags
    ctx.Product.Add(item)
Next
ctx.SaveChanges()

The point that I’m trying to make is:

  • In LINQ to SQL, it will first try to update
    old ones (instead of deleting them from DB). Then insert extra tags.
  • But in Entity Framework, it create and send one query per each “remove” and one
    query per each “add“.

EF doesn’t calculate the updates, but does as it is told to do(no more). it will send lots of queries through SQL so it will rise my auto number column for no reason.
I know that i can do some logic for the second problem, which then I prefer LINQ to SQL in that way.
But I cant do anything about queries pass to SQL. It sound it is not optimized.

I want Code-First combine with these features that LINQ to SQL currently have(calculating stuff before commit). Any suggestion? Have I done anything wrong in EF code? Or is it gonna be like LINQ to SQL in commit changes in RTM version?

UPDATE
If you don’t agree with this behavior please say so and leave a comment.
And If you need more information, please tell me to provide some.

I update this post cause I’m still waiting for an answer. thanks for your time.

  • 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-23T14:39:21+00:00Added an answer on May 23, 2026 at 2:39 pm

    You should use batch operation for this:

    SaveChanges(SaveChangesOptions.Batch);
    

    Read more at msdn.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using Entity Framework and am running into this issue: The relationship between
I met an interesting issue about C#. I have code like below. List<Func<int>> actions
I'm new to Entity Framework and am trying to figure things out. I have
Development environment is C# 3.5 with a SQL Server 2008 database and Entity Framework.
I have had a customer contact me about a bug in my application which
I have an issue that i'm about to pull my hair out over, ok
i have a input tag which is non editable, but some times i need
I'm implementing a DAL using the Entity Framework. We have some DAL classes (I
I have an issue that is driving me a bit nuts: Using a UserProfileManager
We have an issue using the PEAR libraries on Windows from PHP . Pear

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.