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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:32:45+00:00 2026-05-22T17:32:45+00:00

I am using linq to select a bunch of objects by Id through a

  • 0

I am using linq to select a bunch of objects by Id through a facade object. This facade has a function GetObjectById(string id) which returns a MyObject. I select a bunch of object in one query based on a list of ids:

IEnumerable<MyObject> objects = 
   from id in ids   
   select facade.GetObjectById(id);

Then later I set some value on my objects like so:

foreach(MyObject object in objects)
{
  object.someValue = "banaan";
}

Later when I inspect the objects IEnumerable, someValue is not set to “banaan”.

It looks like it has something to do with the deferred execution of linq because when I put .ToList() behind the first query I does work. However, I thought I should be able to do something like this. What am I doing wrong here? Or is my understanding of how you should use linq wrong?

Thanks in advance.

  • 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-22T17:32:46+00:00Added an answer on May 22, 2026 at 5:32 pm

    Sure it is the problem of deferred execution. If the query is executed again it will again call your facade method during and if the facade method loads data from somewhere (= create new instances) your former changes are lost. Your foreach is first execution and inspection outside of the first foreach is second execution.

    You must call ToList if you want to operate on the same instances in such scenario.

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

Sidebar

Related Questions

I need to replicate a T-SQL statement that has an inner select, using LINQ:
I want to make this select using linq: Select cd.name from Content c, ContentDetail
How can I write this in the simplest way using LINQ? SELECT MAX(Game_id) AS
How can you write this query using a lambda expression or LINQ: SELECT *
I am using Linq like this: IQueryable<Rentals> rentals = from r in context.Rentals select
I'm using LINQ to XML. This is the line which I'm having problems: var
I am using Linq to select and process lines from a text file. My
How to select all columns from tables in join using linq Sql: select CTRL_RUN_JOB.*,
Using LINQ to SQL db.Products.Where(c => c.ID == 1).Skip(1).Take(1).ToList(); executes SELECT [t1].[ID], [t1].[CategoryID], [t1].[Name],
Trying to read an RSS and select information using Linq but can't seem to

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.