Link to home
Start Free TrialLog in
Avatar of nikomanek
nikomanekFlag for Afghanistan

asked on

How do I pass an aggregate Linq query to my view

Hi,
I am trying to create a view from two tables in my database. I am using EF4 and ASP.NET MVC 3. Now I query these 2 tables and need to return a view model which contains all columns from the Report table and the business name column from the Customers table. In my view I just want to add one model name. How do I go about it? The attached code of course only returns the report data. So how do I get the one column from the Customers table in the same model (or meta model?)?
public IEnumerable<Report> GetMyReports(int resellerid)
        {
            ReportsAndName repn = new ReportsAndName();
            var reports = from c in entities.Customers
                          from r in entities.Reports
                          where c.CustID == r.CustomerID &&
                          c.Reseller_id == resellerid
                          select r;// String.Format("{0} - {1}", r, c.Business_name);
            
            return reports;

Open in new window

Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi nikomanek;

Do you want the results of the query, reports, to be a collection of type ReportsAndName?

Fernando
Avatar of nikomanek

ASKER

Hi, sorry, the ReportsAndName is a leftover from one of my attempts to create a repository which contains Reports and Customers. Did not really work.

I have entities which are from a EF4 model generated from the Customer and Report table and I would like to have all reports and the business name from Customers in my result.
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect, thank you!
Not a problem, glad I was able to help.