2011-06-30 155 views
0

LINQ库模式帮助下,我在我的仓库下面的方法,从我的数据库返回两个对象的组合,MVC2 /初学者

public IQueryable <ICustomersAndSitesM> CustomerAndSites 
    { 
     get 
     { 
      return from customer in customerTable 
        join site in customerSitesTable 
         on customer.Id equals site.CustomerId 
        select new CustomersAndSitesMix(customer, site); 
     } 
    } 

这是ICustomerAndSitesM

interface ICustomersAndSitesM 
{ 
    IQueryable<Customer> Customers { get; } 
    IQueryable<CustomerSite> CustomerSites { get; } 
} 
我的界面代码

Im正在努力研究如何以及在哪里定义CustomersAndSitesMix,这应该是一个单独的类或接口中的方法吗?并且需要为客户和客户两方面定义?

回答

0

我会将CustomersAndSitesMix设置为一个类,其中包含您需要的其他两个表中的所有属性。我不知道为什么你需要这个接口,但我也会将你方法的返回类型改为List<CustomersAndSitesMix>,并在你的LINQ查询的末尾添加一个ToList()。然后你会返回两个表的内部连接,这可能是你想要的,或者你可能想要添加一个论证,说CustomerID到你的函数,所以你可以通过它,并只获得一个子集。