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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:25:37+00:00 2026-05-23T07:25:37+00:00

Say I have a table in a database called TestDB with a table called

  • 0

Say I have a table in a database called TestDB with a table called Table1 which contains two columns

ID
Name

In this table ,there is two row,

ID 1 and Name 'Row1'
ID 2 and Name 'Row2'

If this is my code

var currObj = Table1.Where(o => o.Name.Contains("Row1")).FirstOrDefault();
currObj.Name = "Row1a";

var a = Table1.Where(o => o.Name.Contains("Row1a")).FirstOrDefault();
var b = Table1.Local.Where(o => o.Name.Contains("Row1a")).FirstOrDefault();

a is going to return null, whereas b is going to return a value.

if I do this though

var c = Table1.Where(o => o.Name.Contains("Row2")).FirstOrDefault();
var d = Table1.Local.Where(o => o.Name.Contains("Row2")).FirstOrDefault();

then c will return something, but d will not.

For me, this seems unintuitive because there is two different places the data could be. For every query I do, I have to look in the database, and the Local object and merge them together. Like if it’s changed in the local object, I have to take that into account. Does Entity Framework have any mechanism for this, which would consider BOTH the data in the database AND the local at the same time?

So if I went

var e =  Table1.AMagicSolution.Where(o => o.Name.Contains("Row1a")).FirstOrDefault();
var f = Table1.AMagicSolution.Where(o => o.Name.Contains("Row2")).FirstOrDefault();

then e and f would both return something (f from the database and e from the Local object)

  • 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-23T07:25:37+00:00Added an answer on May 23, 2026 at 7:25 am

    Your expectation is little bit strange. EF context works like a unit of work = it is used to process single logical transaction and because of that you should try to design your application in the way that it knows if the record is in the local storage or not.

    If for any reason your application doesn’t know if the record is in the local storage you should always separate queries to the local storage and to the database! Reasons are performance and unnecessary roundtrips to the database. Use helper like in following example to query the local storage first and only if record is not present in the local storage query the database:

    public static Table1 AMagicSolution(this IQueryable<Table1> query, string name)
    {
        var item = Table1.Local.Where(t => t.Name.Contains(name)).FirstOrDefault(); 
        if (item != null)
        {
            item = Table1.Where(t => t.Name.Contains(name)).FirstOrDefault();
        }
    
        return item;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a database called Poll and have these two table structures. poll
lets say I have a table called table1 and it's corresponding columns are col1,
Lets say I have a table in a sql server 2000 database called TransactionType:
Let's say I have a table in my database called Orders that has the
Lets say I have a database table called Scrape possibly setup like: UserID (int)
This question can best be asked by example. Say I have a database table
Say I have at database table containing information about a news article in each
I have a field (say, foo) in a table in a SQL Server database
Let's say I have two tables: Report Comment And assuming I have a database
Let's say I have DatabaseA with TableA, which has these fields: Id, Name. In

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.