开发者

MVC2/LINQ Repository pattern help for a beginner

I have the following method in my repository that returns a mix of two objects from my database,

  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);
        }
    }

This is my interface code for the ICustomerAndSitesM

 interface ICustomersAndSitesM
{
    IQueryable<Customer> Customers { get; }
    IQueryable<CustomerSite> CustomerSites { get开发者_开发技巧; }
}

Im struggling with working out how and where to define CustomersAndSitesMix, should this be a seperate class or a method in the interface? and will that need to have definttions for both the customer and customer site?


I would set CustomersAndSitesMix up as a class with all the properties from your other two tables that you need. I am not sure why you are needing this interface, but I would also change the return type of your method to List<CustomersAndSitesMix> and add a ToList() on the end of your LINQ query. Then you would return an inner join of both tables, which may be what you want or you may want to add an arguement, say CustomerID to your function so you could pass it in and get only a subset.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜