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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:18:44+00:00 2026-05-11T14:18:44+00:00

im using linq to sql i have a Mission entity, which holds a collection

  • 0

im using linq to sql i have a Mission entity, which holds a collection of assignments. lets say i went to query the total duration of all the assignments per mission.

and i’ve written the following query:

return db.Missions.Select(m => new MissionNameDays()     {         Name = m.MissionName,         Days = m.Assignments.Sum(a => a.Duration())     }); 

duration is simply defined as (to keep it simple)

public partial class Assignment {     public int Duration()     {         return 1;     } } 

running this code gives me the following exception:

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

i’ve noticed that if i omit the Duration() from the query (aka

Days = m.Assignments.Sum(a => 1) 

it works OK
any ideas about the cause of this?

  • 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. 2026-05-11T14:18:45+00:00Added an answer on May 11, 2026 at 2:18 pm

    The Duration property is not expressible in a SQL statement since it isn’t a table property. Since it is a method on Assignments, the expression parser cannot correctly turn it into a valid SQL expression. Presumably there is some column in the Assignments table from which Duration will be calculated. Try using the same expression that you use to calculate Duration in your Select expression.

    return db.Missions.Select(m => new MissionNameDays()     {         Name = m.MissionName,         Days = m.Assignments.Sum(a => a.LengthInMinutes / 1440 )     }); 

    Alternatively, you can finalize the query then do the select using LINQToObjects which will work with non-columnar properties/methods. Since you’re not filtering the Missions in this query, I think I’d go with this method.

    return db.Missions.ToList().Select(m => new MissionNameDays()     {         Name = m.MissionName,         Days = m.Assignments.Sum(a => a.Duration())     }); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 90k
  • Answers 91k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should use a linked list. Adding an item to… May 11, 2026 at 6:10 pm
  • Editorial Team
    Editorial Team added an answer I assume that by "unix timestamp formatted date" you mean… May 11, 2026 at 6:10 pm
  • Editorial Team
    Editorial Team added an answer I found that my problem was that I was not… May 11, 2026 at 6:10 pm

Related Questions

I'm using Linq to SQL. I have a DataContext against which I am .SubmitChanges()'ing.
I have a table in the database that I'm retrieving using LINQ to SQL,
I'm using LINQ to Entities (not LINQ to SQL) and I'm having trouble creating
I'm trying to work out how to validate a user in my application but

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.