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

  • Home
  • SEARCH
  • 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 8189883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:26:03+00:00 2026-06-07T03:26:03+00:00

I use the code below to get records from two tables but I want

  • 0

I use the code below to get records from two tables but I want to have the result in a List. I used the code below, but this error occured:

Cannot implicitly convert type
System.Collections.Generic.List<AnonymousType#1> to
System.Collections.Generic.List<QuickRoutes.DAL.Route>

public List<Route> GetAllForUser(Guid userId)
{
    // var result = new List<Route>();
    aspnetdbDataContext aspdb = new aspnetdbDataContext();
    List<Route> result  = (from r in aspdb.Routes
                where r.UserId == userId
                join t in aspdb.TrackPoints on r.RouteId equals t.RouteFK
                select t.TrackPointId,t.RouteFK,t.TrackTime,t.Longitude,t.Latitude,t.Elevation, r.SourceName).ToList();
    return result;
}

EDIT:

I want to match my query with this class:

namespace QuickRoutes.Entities
{
    public enum RouteType
    {
        Route, Waypoints, Track
    }

    public sealed class Route
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public DateTime Time { get; set; }
        public List<TrackPoint> TrackPoints { get; set; }
        public Guid UserId { get; set; }
        public string GpxData { get; set; }
        public RouteType RouteType { get; set; }


        public Route(int id)
        {
            Id = id;
            TrackPoints = new List<TrackPoint>();
        }
......

but if I change my code to this one,It doesn’t work too

List<Route> result = (from r in aspdb.RouteLinqs
                                  where r.UserId == userId
                                  join t in aspdb.TrackPointlinqs on r.RouteId equals t.RouteFK
                                  select r).ToList();

to be honest I want to change this function that is written with SQL to LINQ,have any better idee?

namespace QuickRoutes.Entities
{
    public enum RouteType
    {
        Route, Waypoints, Track
    }

    public sealed class Route
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public DateTime Time { get; set; }
        public List<TrackPoint> TrackPoints { get; set; }
        public Guid UserId { get; set; }
        public string GpxData { get; set; }
        public RouteType RouteType { get; set; }


        public Route(int id)
        {
            Id = id;
            TrackPoints = new List<TrackPoint>();
        }
......
  • 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-07T03:26:04+00:00Added an answer on June 7, 2026 at 3:26 am

    It’s because your projection (what you’re selecting) isn’t the same as a Route (what you’re trying to return);

    If you wish to return a Route Change your select to:

    select r
    

    If you wish to return your joined projection, you’l have to create a new type, and return that:

    e.g:

    public class RouteTrack
    {
        public TrackPointId ...
        public RouteFK ...
        public TrackTime ...
    }
    

    And return a List<RouteTrack> from your method, and change your select to:

    select new RouteTrack { TrackPointId = t.TrackPointId .... }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I use below code query database, I cannot get any result, but I
I have a doubt i use the following piece of code get data from
I have a strange behavior. The code below worked from a long time but
Is there an ide/site that I can use to analyse code below and get
I use below code to get photo's path and id: String[] projection = {MediaStore.Images.Media._ID,
The code below is what I am trying to use in order to get
I use this code below to hide stream url of songs for my wordpress
As a PHP developer, I always use the code below whenever I want to
I use below code to update listview. setListAdapter(MyAdapter); MyAdapter.notifyDataSetChanged(); getListView().setEmptyView(empty); But each time update,
I want to use JBoss tools in Eclipse to generate java code from DDL.

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.