我的GUI正在调用一个执行一些linq工作的服务项目,并将数据返回到我的GUI。但是,我正在与该方法的返回类型作斗争。经过一些阅读后,我有这个作为我的方法:Linq和返回类型
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;
}
但是,我的来电者有点争斗。我认为我搞砸了返回类型,或者没有很好地处理调用者,但它并不像我希望的那样工作。
这就是我试图从我的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();
但是,我的foreach和acc不起作用。 acc不知道我在该方法中设置的名称,说明和ID。我至少接近对吗?
不,同一个项目,但我想将它们分成不同的项目。所以,假设他们现在是分开的。 – Craig 2011-01-08 05:54:39
你的服务是在远程?最好使用`var`代替这个参数类型。 – 2011-01-08 05:55:48
我想知道是否应该建立一个共享类lib,它具有'传输对象'。所以在我的方法中,我获取数据,并将它们加载到List中,然后返回该数据。那么执行linq的项目和GUI都会知道类型? –
Craig
2011-01-08 05:55:58