How to create anonymous objects of type IQueryable using LINQ

Posted by Soham Dasgupta on Stack Overflow See other posts from Stack Overflow or by Soham Dasgupta
Published on 2010-05-27T14:06:47Z Indexed on 2010/05/27 14:11 UTC
Read the original article Hit count: 187

Filed under:

Hi, I'm working in an ASP.NET MVC project where I have created a two LinqToSQL classes. I have also created a repository class for the models and I've implemented some methods like LIST, ADD, SAVE in that class which serves the controller with data. Now in one of the repository classes I have pulled some data with LINQ joins like this.

private HerculesCompanyDataContext Company = new HerculesCompanyDataContext();
private HerculesMainDataContext MasterData = new HerculesMainDataContext();
public IQueryable TRFLIST()
{
var info = from trfTable in Company.TRFs
       join exusrTable in MasterData.ex_users on trfTable.P_ID equals exusrTable.EXUSER
       select new 
           {
               trfTable.REQ_NO,
               trfTable.REQ_DATE,
               exusrTable.USER_NAME,
               exusrTable.USER_LNAME,
               trfTable.FROM_DT,
               trfTable.TO_DT,
               trfTable.DESTN,
               trfTable.TRAIN,
               trfTable.CAR,
               trfTable.AIRPLANE,
               trfTable.TAXI,
               trfTable.TPURPOSE,
               trfTable.STAT,
               trfTable.ROUTING
           };
    return info;
}

Now when I call this method from my controller I'm unable to get a list. What I want to know is without creating a custom data model class how can I return an object of anonymous type like IQueryable. And because this does not belong to any one data model how can refer to this list in the view.

© Stack Overflow or respective owner

Related posts about asp.net-mvc