Linq and returning types

Posted by cdotlister on Stack Overflow See other posts from Stack Overflow or by cdotlister
Published on 2011-01-08T05:51:16Z Indexed on 2011/01/08 5:53 UTC
Read the original article Hit count: 208

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ