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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:16:31+00:00 2026-06-03T19:16:31+00:00

I have two tables, for Users and Songs. I need to JOIN them both

  • 0

I have two tables, for Users and Songs. I need to JOIN them both on the UserID column and return a list to the view. I tried writing an anonymous type but I’m getting an error about:

‘Only parameterless constructors and initializers are supported in LINQ to Entities.’

How can I JOIN and return to list?

 public class User
    {
        [Key]
        public virtual Guid UserId { get; set; }

        [Required]
        public virtual String Username { get; set; }

        [Required]
        public virtual String Email { get; set; }

        [Required, DataType(DataType.Password)]
        public virtual String Password { get; set; }

}





 public class Song
    {
        public int SongId { get; set; }

        public virtual Guid UserId { get; set; }

        public string SongTitle { get; set; }

    }

I tried implementing a method like this one here:

What is the return type of my linq query?

The query I ended up with was:

var query = from u in db.Users
                        join s in db.Songs
                        on u.UserId equals s.UserId
                        select new HomeSongList(s.SongId, s.UserId, u.Username);


            return View(query.ToList());
  • 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-03T19:16:34+00:00Added an answer on June 3, 2026 at 7:16 pm

    You can’t use parameterized constructors but you can use initializers, if you change your select to the following it should work.

    select new HomeSongList{SongId=s.SongId, UserId=s.UserId, Username=u.Username};
    

    Note that this will require that HomeSongList has a parameterless constructor and writable properties.

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

Sidebar

Related Questions

hope someone can help. I have two tables: Users -UserID -UserName UsersType -UserTypeID -UserID
I have two tables like this: Table Name: users emx | userid --------------- 1
I have two tables, one is a list of songs. The other is a
I have two tables. Table A: Contains a list of songs, song artwork, mp3
I have two tables Users and Expenses in the backend. UserId is a foreignKey
Hi I have two tables (users & friends) I need to connect to the
I have two tables, one containing a list of different options users can select
Hopefully a simple question. I have several models, two of them, :users and :songs
Below I have two tables users and users_profiles Both are innoDB and collation: utf8_general_ci
I have two tables that need to be related--a users table and an address_book

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.