Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 825945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:20:09+00:00 2026-05-15T03:20:09+00:00

I’m working in an ASP.NET MVC project where I have created a two LinqToSQL

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:20:10+00:00Added an answer on May 15, 2026 at 3:20 am

    You cannot return an object of “anonymous type”. Please see this previous post of mine that address this situation, where it seems anonymous types will allow us to cheat a little bit on strong typing, but they do not.

    Yes, moving from flexible types (like DataTables) to strongly typed objects is a huge part of your solution strategy. With LINQ-To-SQL, you should be able to pretty easily get back strongly typed entity objects. Your repository methods need to return specifically typed IQueryable interfaces,like IQueryable<TRF>, not just IQueryable. Or, a repository method could just return a single TRF entity object, or a list of these objects.

    Keep in mind that anonymous types and implicitly typed variables are two very different things. An anonymous type is created for you by the compiler behind the scenes. In this case, don’t put your data into an anonymous type, like you do in your example LINQ query. Assuming your entity is trfTable, try this:

    public IQueryable<trfTable> TRFLIST()
    {
        var info = from trfTable in Company.TRFs
            join exusrTable in MasterData.ex_users on trfTable.P_ID equals exusrTable.EXUSER
            select new trfTable
        return info;
    }
    

    The benefit of this is that it takes massive advantage of the nature of IQueryable, in that criteria added outside your repository will actually be added to the generated query. It’s cool. However, there is some good debate about whether this is the best way to do it.

    Note that info here is implicitly typed by the compiler, but it is not an anonymous type. It is an IQuerable<trfTable>. This is the key distinction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.