c# - LINQ to SQL: Grouping and limiting a record set -


I am using SQL from SQL and I have a stored procedure that brings back a result set that Looks like:

  Type field 1 field 2 5 1 1 6 2 0 21 0 0  

I hope to do some things with this record set :

1) There are 3 groups of results, which have values ​​in both Field 1 and Field 2, Field 1 has one value, but Field 2 is not, and no field 1 and field 2 is Shu The Price.

2) I'm only interested in a subset of types I have a type of ID that I see (say 5 and 21 for this example). Types of values ​​are stored in an calculation now, but I can take them to the better data type if appropriate.

I have found where I can group each group but how limited is the type of type, so I will only bring people back to whom I am interested.

Here's what I have:

  var results = all in the dataContext.sp (.. variable ..) all in the list to all group groups grp1 = (Select from a list where a.field1! = 0 & amp; a.field2! = 0, select a) grp2 = (in the list B in where b.field1 = 0 & amp; amp; b.field2 ! = 0 Select B) Let's go to grp3 = (from the list in C. Where c.field1 == 0 & amp; amp; amp; c.field2 == 0 select c) New {grp1, grp2, Grp3}}  

Any help is appreciated.

Do you really want all data for those groups? If so, you can also well return grouping back to annot - just filter in SQL:

  // Interesting typing is an array or an interesting type of list var query = Db.Whatever the (entry => interesting type.company (type of entry) // I think you are not interested in this group & amp;! (Entry.field1 == 0 & amp; amp; Amp; Entry Field2 == 1)); Var grouped = query.AsEnumerable () .GroupBy (login = & gt; new {entry.Field1, entry.Field2});  

GroupB option is to use ToLookup:

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

then:

  var values00 = lookup [new {field1 = 0, field2 = 0}];  

(The value of 100 will be one IEnumerable will be of your login type.)

If you only type For each field group you are interested in, you can change the lookup in the following:

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

You can get the values00 in the same way, but each entry will be the type instead of the full record.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -