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

  • Home
  • SEARCH
  • 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 6124367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:07:30+00:00 2026-05-23T16:07:30+00:00

Consider the following code. var items = from i in context.Items select i; var

  • 0

Consider the following code.

var items = from i in context.Items
            select i;
var item = items.FirstOrDefault();
item.this = "that";
item.that = "this";

var items2 = from i in context.Items
             where i.this == "that"
             select i;
var data = items2.FirstOrDefault();

context.SaveChanges();

I’m trying to confirm that items2 will not include my modifications to item. In other words, items2‘s copy of item will not include the unsaved changes.

  • 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-23T16:07:30+00:00Added an answer on May 23, 2026 at 4:07 pm

    Have you tried it? =)

    By default, your objects are being tracked and cached by the context, so that the objects in your second query actually do reflect changes in the first.

    You may want to call context.Items.AsNoTracking() on the one of your two “items” to get the behavior you want.

    Edit: Actually, this is a strange question. I just noticed that your items2 hasn’t even hit the database yet, since you haven’t called ToList() or FirstorDefault(). It remains an IQueryable that will hit the database after your code snippet and will therefore contain the changed value.

    HOWEVER, if you call ToList() on items2, you’ll encounter the caching scenario I outlined above.

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

Sidebar

Related Questions

Consider following piece of code: declare @var bit = 0 select * from tableA
Consider the following code: var Products_First = (from Entities.Product p in myContext.Product select p);
Please consider the following code (also in this fiddle ): var viewModel = {
Consider the following code: $(a).attr(disabled, disabled); In IE and FF, this will make anchors
Consider the following code: client.Send(data, data.Length, endpoint); byte[] response = client.Receive(ref endpoint); While, according
Consider the following code and its output: Code #!/usr/bin/perl -w use strict; use Data::Dumper;
Noob question: Consider the following C# code: public IEnumerable<xpto> CalculatedList { get { foreach(var
Consider the following code: var Widget = new Class({ Implements: [Options], options: { name
Consider the following code: var sentences = [ 'Lorem ipsum dolor sit amet, consectetur
Consider the following code: for (var i = 0; i < 3; i++) {

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.