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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:40:12+00:00 2026-05-12T07:40:12+00:00

I’m using LINQ to SQL and I have a stored procedure which brings back

  • 0

I’m using LINQ to SQL and I have a stored procedure which brings back a result set that looks like so:

Type    Field1   Field2
 5        1        1
 6        2        0
21        0        0

I’m hoping to do a few things with this record set:

1) Have 3 groups of results, one that has values in both field1 and field2, one that has a value in field1 but not field2 and one that has zeros in field1 and field2.

2) I’m only interested in a subset of types. I have a list of type id’s I’m looking for (say 5 and 21 for this example). Right now the type values are stored in an enumeration but I can move them to a better data type if appropriate.

I’ve gotten to where I can group each set but I’m unsure of how to limit the types so I only bring back those I’m interested in.

Here’s what I have:

var result = from all in dataContext.sp(..variables...)
           group all by all into list
           let grp1 = (from a in list
                      where a.field1 != 0 && a.field2 != 0
                      select a)
           let grp2 = (from b in list
                     where b.field1 == 0 && b.field2 != 0
                     select b)
           let grp3 = (from c in list
                      where c.field1 == 0 && c.field2 == 0
                      select c)
           select new { grp1, grp2, grp3 };

Any help is appreciated.

  • 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-12T07:40:12+00:00Added an answer on May 12, 2026 at 7:40 am

    Do you actually want all the data for those groups? If so, you might as well do the grouping back in .NET – just filter in SQL:

    // Assuming interestingTypes is an array or list of the interesting types
    var query = db.Whatever.Where(entry => interestingTypes.Contains(entry.Type)
                                  // I understand you're not interested in this group
                                  && !(entry.Field1==0 && entry.Field2==1));
    
    var grouped = query.AsEnumerable()
                       .GroupBy(entry => new { entry.Field1, entry.Field2 });
    

    An alternative to GroupBy is to use ToLookup:

    var lookup = query.AsEnumerable()
                      .ToLookup(entry => new { entry.Field1, entry.Field2 });
    

    Then:

    var values00 = lookup[new { Field1=0, Field2=0 }];
    

    (Then values00 will be an IEnumerable<T> of your entry type.)

    If you’re only interested in the types for each field group, you could change the lookup to:

    var lookup = query.AsEnumerable()
                      .ToLookup(entry => new { entry.Field1, entry.Field2 },
                                entry => entry.Type);
    

    You’d fetch values00 in the same way, but each entry would be the type rather than the whole record.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6
I have a text area in my form which accepts all possible characters from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.