@BrokenGlass is correct that the root of the problem is that you are using an anonymous type. This leads to the fact that you are using a non-generic version of IEnumerable, which does not know what type of objects are.
Instead of using dynamic though (which requires .NET 4.0, which may or may not be a problem for you), I would recommend creating an actual Account class.
That way you can return an IEnumerable<Account> instead of an IEnumerable . Then you can use the properties, as he knows that this is an account.
After creating the Account class, your method will look like this:
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 may remain the same.
I thought I should indicate that var does not work the way you probably think. The type of the variable is still determined by compilation time, which means (for the most part) it's just a shortcut. Your example will be identical if you used object instead of var , because IEnumerable can only contain object .
If you work in .NET, I would recommend following the .NET naming conventions, although AccountId instead of account_id , but this will not affect whether it works or not.
source share