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

The Archive Base Latest Questions

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

My GUI is calling a service project that does some linq work, and returns

  • 0

My GUI is calling a service project that does some linq work, and returns data to my GUI. However, I am battling with the return type of the method. After some reading, I have this as my method:

public static IEnumerable GetDetailedAccounts()
 {
 IEnumerable accounts =(from a in Db.accounts
                        join i in Db.financial_institution on  
                            a.financial_institution.financial_institution_id
                               equals i.financial_institution_id
                        join acct in Db.z_account_type on a.z_account_type.account_type_id 
                               equals acct.account_type_id
                        orderby i.name
                        select new 
                             {
                              account_id = a.account_id, 
                              name = i.name, 
                              description = acct.description
                              });
            return accounts;
}

However, my caller is battling a bit. I think I am screwing up the return type, or not handling the caller well, but it’s not working as I’d hoped.

This is how I am attempting to call the method from my GUI.

IEnumerable accounts = Data.AccountService.GetDetailedAccounts();

Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Accounts:");
Console.ForegroundColor = ConsoleColor.White;

foreach (var acc in accounts)
  {
   Console.WriteLine(string.Format("{0:00} {1}", acc.account_id, acc.name + " " + acc.description));
  }

int accountid = WaitForKey();

However, my foreach, and the acc – isn’t working. acc doesn’t know about the name, description and id that I setup in the method. Am I at least close to being right?

  • 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-19T00:53:23+00:00Added an answer on May 19, 2026 at 12:53 am

    @BrokenGlass is correct that the root of the issue is that you’re using an anonymous type. That results in you using the non-generic version of IEnumerable which doesn’t know what type the objects are.

    Rather than using dynamic though (which requires .NET 4.0 which may or may not be an issue for you), I would recommend creating an actual Account class.

    That way you can return an IEnumerable<Account> instead of just IEnumerable. Then you’ll be able to use the properties since it knows that it’s an Account.

    Once you create the Account class your method then becomes:

    public static IEnumerable<Account> GetDetailedAccounts()
    {
        IEnumerable<Account> accounts = (from a in Db.accounts
                        join i in Db.financial_institution on a.financial_institution.financial_institution_id
                            equals i.financial_institution_id
                        join acct in Db.z_account_type on a.z_account_type.account_type_id equals
                            acct.account_type_id
                        orderby i.name
                        select new Account {account_id = a.account_id, name = i.name, description = acct.description});
        return accounts;
    
    }
    

    Then the calling code can remain the same.

    I thought I should point out that var doesn’t work the way you probably think it does. The type of the variable is still determined compile-time, which means (for the most part) it’s just a shortcut. Your example would be identical to if you had used object instead of var because IEnumerable can only contain object.

    If you’re working in .NET I’d recommend follow .NET naming conventions though so AccountId instead of account_id but that won’t affect whether it works or not.

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

Sidebar

Related Questions

I have a large GUI project that I'd like to port to Linux. What
A GUI driven application needs to host some prebuilt WinForms based components. These components
Which GUI framework/library would you choose if you were to start your new project
I am creating a GUI for a machine that runs remote (WinXP) or on
Terminology: What do you call this type of web gui feature? I'm trying to
Calling a GUI app using [DllImport( advapi32.dll, EntryPoint = CreateProcessAsUser, SetLastError = true, CharSet
I have a build script calling xcodebuild. that works, but I want to also
I refactored some code, and now I get this error when calling a function.
I need a GUI system that contain: a tree list that each item of
I'd like a GUI framework that works on both Windows and Linux. I'm confused

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.