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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:24:47+00:00 2026-06-17T21:24:47+00:00

I’m pretty new to LINQ to SQL, and until recently have had no problems.

  • 0

I’m pretty new to LINQ to SQL, and until recently have had no problems. Writing in C#.

I’ve got a model helper .cs file. I am attempting to create a public list that I can base a view off of.

Here’s the code in the model helper (with extraneous, working, content removed:

using System;
using System.Collections.Generic;
using System.Linq;

namespace sample_runs.Models {
    partial public class SampleRunsDataContext {
        public List<attendee> GetMyRuns(int me) {          
            var mine = (from a in attendees
                       join s in sample_runs 
                            on a.sample_run_id equals s.sample_run_id
                       where a.user_id == me
                       orderby a.sample_run_id descending
                       select new {
                           s.sample_run_id,
                           a.role.role_name,
                           s.sample_run_status.sample_run_status_name,
                           s.project_number,
                           s.run_type.run_type_name,
                           s.description
                       }).ToList();
            return mine;
        }

    }

}

As for the database, consider the two tables involved like this. sample_runs is like a list of parties or events. So, for each line we’ve got all the information for the party. Then, we’ve got a table called attendees, where all the party attendees are listed individually. Each line has information about attendees, including their ‘role’ which is where I suppose the metaphor breaks down. There could be any number of attendees for each party. The database is pretty with foreign keys and your usual variety of normalization.

All I want is, for a given attendee, a list of all the parties they’ve been to. I hope that makes sense.

All my other linq statements and lists in this file are working fine. This one gives me this brand of grief:

Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>'
to 'System.C9ollections.Generic.List<sample_runs.Models.attendee>

I’m confused about whether this should be a public list or something else.

I’m unsure whether

List<attendee>

should really be

List<attendee>

due to the join.

After some research, I’ve played with what the ‘mine’ variable gets sent to, and whether this should be a List<> or IENumerable<> etc etc etc. I am woefully lost.

Just for reference, this is what I want to do with ‘GetMyRuns’, in the controller:

    public ActionResult myruns() {
        return View(db.GetMyRuns(someintvar));
    }

And then I figure I’ll build a strongly-typed view and go from there.

I know this may be a softball question, but I’m incredibly grateful for any help you may be able to offer me.

Thank you.

  • 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-17T21:24:48+00:00Added an answer on June 17, 2026 at 9:24 pm

    As the error indicates, mine is a list of annonymous objects, while you should be returning a list of attendee objects. The select in your query creates the annonymous object (note the absence of any type indication):

    select new /* NO TYPE */ {
        s.sample_run_id,
        ...
    }
    

    The solution to your problem would depend on how exactly your application is structured, but one way to fix it would be by creating some kind of DTO (Data Transfer Object) list and returning it instead:

    public List<AttendeeDto> GetMyRuns(int me)
    {
        var mine = (from a in attendees
                    join s in sample_runs 
                    on a.sample_run_id equals s.sample_run_id
                    where a.user_id == me
                    orderby a.sample_run_id descending
                    select new AttendeeDto
                    {
                        SampleRunId = s.sample_run_id,
                        RoleName = a.role.role_name,
                        SampleRunStatusName = s.sample_run_status.sample_run_status_name,
                        ProjectNumber = s.project_number,
                        RunTypeName = s.run_type.run_type_name,
                        Description = s.description
                    }).ToList();
    
            return mine;
        }
    }
    

    Your AttendeeDto class would look like this:

    class AttendeeDto
    {
        public int SampleRunId { get; set; }
        public string RoleName { get; set; }
        public string SampleRunStatusName { get; set; }
        public int ProjectNumber { get; set; }
        public string RunTypeName { get; set; }
        public string Description { get; set; }
    }
    

    And BTW – I hope you never actually name integer variables me and List variables mine in production code? 😉

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

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I want use html5's new tag to play a wav file (currently only supported
I have a reasonable size flat file database of text documents mostly saved in
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
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've got a string that has curly quotes in it. I'd like to replace

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.