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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:47:16+00:00 2026-05-24T03:47:16+00:00

I have the following LINQ query that I am using to construct a structure

  • 0

I have the following LINQ query that I am using to construct a structure to stuff into a JavaScript grid library which is irrelevant for this example, but I figured I would still explain that.

var output = myObjects.Select(
    p => new RowModel
    {
         ID = p.LeadUID,
         Cells =
             new CellCollection(fields,
                p.myDataDatas.Where(q => q.myField.ParentUID == null).Select(
                    q => new CellModel
                             {
                                 Value = q.Value,
                                 Name = q.myField.Description,
                                 Display = q.myField.Description
                             }).ToList()
                ,
                new CellModel
                    {
                        Name = "Campaign",
                        Display = "Campaign",
                        Value = p.Campaign.Name
                    }
                ,
                new CellModel
                    {
                        Name = "CampaignEnabled",
                        Display = "CampaignEnabled",
                        Value = p.Campaign.IsActive.ToString()
                    },
                new CellModel
                    {
                        Name = "Date Received",
                        Display = "Date Received",
                        Value = p.DateAdded.ToString()
                    }
                ,
                new CellModel
                    {
                        Name = "Is Valid",
                        Display = "Is Valid",
                        Value = BooleanMap[p.IsValid]
                    }
                ,
                new CellModel
                    {
                        Name = "Invalid Reason",
                        Display = "Invalid Reason",
                        Value = p.InvalidReason

                    }
                ,
                new CellModel
                    {
                        Name = "Is Returned",
                        Display = "Is Returned",
                        Value = BooleanMap[p.IsReturned]
                    }
                ,
                new CellModel
                    {
                        Name = "Return Reason",
                        Display = "Return Reason",
                        Value =
                            context.MYReturns.SingleOrDefault(
                                l => l.LeadUID == p.MyUID).ReturnReason
                    }
                ,
                new CellModel
                    {
                        Name = "Workflow",
                        Display = "Workflow",
                        Value =
                            context.Stages.SingleOrDefault(
                                s => s.LifecycleStageUID == p.LifecycleStageUID).
                            Name
                    }
                ,
                new CellModel
                    {
                        Name = "WorkflowEnabled",
                        Display = "WorkflowEnabled",
                        Value =
                            context.Stages.SingleOrDefault(
                                s => s.LifecycleStageUID == p.LifecycleStageUID).
                            IsActive.ToString()
                    }
                ,
                new CellModel
                    {
                        Name = "Status",
                        Display = "Status",
                        Value = p.MyStatus.Name
                    }
                ,
                new CellModel
                    {
                        Name = "StatusDeleted",
                        Display = "StatusDeleted",
                        Value = (p.MyStatus.Deleted).ToString()
                    }
                ,
                new CellModel
                    {
                        Name = "LeadSource",
                        Display = "Lead Source",
                        Value = MySourcesMap[p.AccountSourceUID].Name
                    }
                ,
                new CellModel
                    {
                        Name = "LeadSourceEnabled",
                        Display = "LeadSourceEnabled",
                        Value = AccountSoucesEnabledMap[p.AccountSourceUID].ToString()
                    }
                        )
                     }
            );
            var rows = output.ToList();
            return rows;

I would like to expect that my changing the names of most of my variables in the code will not affect the big picture.

My problem that I am facing is SOMETIMES I am getting the following SQLException message:

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

What I am wondering, is where in my query am I doing something wrong that would sometimes(most of the time) work, and then very rarely returns this error message. How can I correctly prevent this from happening?

  • 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-05-24T03:47:17+00:00Added an answer on May 24, 2026 at 3:47 am

    use the DataContext.Log property to display the sql generated by your query. You most likely have a sub-query that is generating more than one result when only one result is valid. For example the following sql will fail if more than one result is returned in the sub-query:

    Select * from orders where customer_id = 
      (select customer_id from customer where name ='bob')
    

    The equality of the where clause in the main query makes no sense if there is more than one result returned from the sub-query.

    You may need to alter the uniqueness of some columns of data in your storage in order to ensure that only one row is returned in the sub-query. Another alternative is to alter your class so that the specific problem property being assigned to is a collection instead of a single value.

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

Sidebar

Related Questions

I have a Premiums table that I attempting to query using the following LINQ-to-SQL:
I have the following LINQ expression that's not returning the appropriate response var query
I have the following query of linq to entities. The problem is that it
I have the following Linq to SQL query, in which I'm trying to do
I have a problem with the following Linq query using Entity Framework: from o
I have the following LINQ query that returns two objects from my database. These
I am using LINQ to EF and have the following LINQ query: var results
I have a linq query which presents data that is present in CustomersRecord Table
I have the following LINQ conditional where clause query that produces a result of
I have a LINQ query that looks like the following: DateTime today = DateTime.UtcNow;

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.