c# - Complex LINQ to SQL query to return List<T> -
I'm writing a WP 8 that will return the list to the WCF service. I want to select all teachers from the database and then I would like to return to each other from the list created, which will show 5 teachers whose maximum income ( maxInc
) is the closest to me ( MyMaxInc
). For example, if MyMaxInc = 200
and I have 225 with user, user 2 240 and user 3 to 210, then in the returned list the teachers will be shown in the following order: user3, user, user2 Mary Service implementation:
public IEnumerable & lt; MTeachers & gt; GetStuffList (integer MyMaxInc, int MyMinInc) {list & lt; MTeachers & gt; StuffList = new list & lt; MTeachers & gt; (); DataClass1DatatUntext Data = New DataCall 1Datacentax (); Int inc = 0; & Lt; MTeachers & gt; Final list = new list & lt; MTeachers & gt; (); {"DTistjob ==" Teacher ") {stufflist.Add (new mTeachers (d.stuffName, (int) d.maxInc, (int) d.minInc," teacher ", Inc.)); Ink ++;}} (Ink> 0) {foreach (mTeachers element in the list of accessories) if () {/ * does not end this bit because do not know to create the next list /} return final list;} and return tap;}
Service interface:
[service contact] Public interface IISIS 1 {[OperationContract] IINMERABLE & lt; mTeachers & gt; GetStuffList (Int MyMaxInc, Int MyMinInc);} [DataContract] Public Clients PublicTransfer; [DataMember] Public String Name; [Datamember] Public at MaxInc; [Database] Public ININC [Datamember] Public String Job; [Database] Public Int Number; Public mTeachers (String Name, Intex, Int Minneck, String job, int number) {this.maxInc = maxInc; This.minInc = minInc; This.Name = name; This.Job = Job; this number = number;}}
Also I have the number
member mTeachers
group to group finalList Created later. For example, when I am creating a list in the loop and group the
private static list & lt; Group & lt; T & gt; & Gt; GetItemGroups & lt; T & gt; (Ienumerable & lt; T & gt; item list, funk & lt; t, string & gt; getKeyFunc)
method.
foreach (mTeachers element in stuffList) if ( ) {/ * This bit did not end because you do not know how to make a second list
with
finalList.AddRange (stuffList .OrderBy (x = & gt; Math.x.maxInc - MyMaxInc). Take (5));
Math Abus (...)
turns negative votes into positive form to be able to compare small and big values at the same time. <5> <5> Take <5> <5> <5> takes 5 first elements, sorted by the minimum difference.
Comments
Post a Comment