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 9281113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:02:31+00:00 2026-06-18T18:02:31+00:00

I have a LINQ to SQL query function combinding to tables, but the function gives an

  • 0

I have a LINQ to SQL query function combinding to tables, but the function gives an error on “return res.ToList();”.

  • imo_no is int
  • position_cordinates is String
  • vessel_id is int
  • equipment is String.

My function:

List<T> GetAllInitialize()
{
    PositionDataClassesDataContext context = new PositionDataClassesDataContext();

    var res = from positions in context.it_positions
              join vessels in context.it_vessels on positions.imo_no equals vessels.imo_no
              select new { positions.imo_no, positions.position_cordinates, vessels.vessel_id, vessels.equipment };

    return res.ToList();
}

enter image description here

  • 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-06-18T18:02:32+00:00Added an answer on June 18, 2026 at 6:02 pm

    Although you can use anonymous types or collections of objects of anonymous type locally with static typing, there is no way to return them from a function without losing the information about their static type.

    If you cannot or for some reason prefer not to create a named class to hold the return data, you need to either return List<dynamic>, or List<object>. Both these approaches have their drawbacks: dynamic will be slower than a comparable statically-typed object, while System.Object would not let you do much with the data that you get back.

    The best solution would be creating a named return type:

    public class PositionData {
         public int ImoNo {get;set;}
         public string PositionCordinates {get;set;}
         public int VesselId {get;set;}
         public string Equipment  {get;set;}
    }
    

    Now your query will look like this:

    select new PositionData {
        ImoNo = positions.imo_no
    ,   PositionCordinates = positions.position_cordinates
    ,   VesselId = vessels.vessel_id
    ,   Equipment = vessels.equipment
    };
    

    The return type of your method would change to List<PositionData>.

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

Sidebar

Related Questions

I have Linq to SQL query which return one field with Url and I
Possible Duplicate: To return IQueryable<T> or not return IQueryable<T> I have LINQ to SQL
I have spent quite a few hours reading and learning about LINQ to XML , but
I have LINQ Query which return result in below format -- Parent1 ----Childs ------key
I have this linq query that appear to be good, haven't tested yet. But
I have LINQ query that returns me the following error: The incoming tabular data
In SQL I have 2 tables. Sport              Athlete SportId          AthleteId SportName    AthleteName Their relation is
I cannot seem to find a way to have LINQ return the value from
I have a LINQ to Entity query that is running really slow. This query
I have a Linq query that looks something like this: var myPosse = from

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.