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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:19:41+00:00 2026-05-23T12:19:41+00:00

I have the following code and it works good: var _data = (from qu

  • 0

I have the following code and it works good:

var _data = (from qu in _que.GetAll(
  u => u.company == "GE" )
  select new {
    qu.name,
    qu.address
});

The signature of the GetALL method is

ICollection<T> GetAll(Expression<Func<T, bool>> predicate);

Now I need to enclose the above in some block so it becomes:

{
    var _data = (from qu in _que.GetAll(
      u => u.company == "GE" )
      select new {
        qu.name,
        qu.address
    });
}
var _abc = _data; <<< doesn't work now

Once I do this then _data becomes local and I can’t access it from outside the block. I assume that what I need to do is to declare _data outside of the block. But what do I declare it too as they type that’s returned and placed into _data is an anonymous type. Is there some way I can declare _data without having to change the query or make up some return type?

  • 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-23T12:19:42+00:00Added an answer on May 23, 2026 at 12:19 pm

    Your question is unclear, but I think I understand it, just about. Personally I try to avoid requiring this, but you can do something like:

    // I'm assuming name and address are strings
    var _data = Enumerable.Repeat(new { name = "", address = "" }, 0);
    _data = null; // Never actually want to use that value
    
    if (someCondition)
    {
        _data = from qu in _que.GetAll(u => u.company == "GE")
                select new { qu.name, qu.address };
    }
    

    So long as you use the same property names and types, the two anonymous types here will be equivalent, so you can perform the second assignment with no problems. Note that I’ve changed the formatting of your query expression – I believe this looks much clearer, as previously it looked like the GetAll argument was part of the query expression itself.

    Given that your query expression is just a single select, I’d probably actually just write:

    _data = _que.GetAll(u => u.company == "GE")
                .Select(qu => new { qu.name, qu.address });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code to create a file and write data into it:
I am new to YAML, and have tried to do a YAML block but
I have this working fine from Linux command line: wkhtmltopdf entry.html output.pdf But the
I have an applet, which I was writing in Java. Recently, I thought that
I`m trying to do a form_for with nested routes following the example of Blog
I was following the Contoso University tutorial on the asp.net website and it all
This is my first website attempt and I've been following a great tutorial while
Background: I am fairly new to Visual Studio 2010 (worked on Lua, LIMSBasic (Labware)
I am testing out the idea of threads, but only in very key spots
I'm trying to dynamically bind mysql_stmt parameters and get the result in an associative

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.