LINQ to SQL in and sorting

Source: Internet
Author: User

In the previous article, the author asked the sorting question about how to sort elements in sequence at the time of in?

 

C #

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. Data. LINQ;

Namespace consoleapplication36
{
Class Program
{
Static void main (string [] ARGs)
{
Dataclasses1datacontext context = new dataclasses1datacontext ();
Context. log = console. out;
VaR result = From S1 in context. Customers where (New String [] {"UK", "Lisboa"}). Contains (s1.city) Select S1;
VaR result2 = customsort (result. tolist (), new string [] {"UK", "Lisboa "});
Foreach (VAR item in result2)
{
Console. writeline (item. City );
}
Console. Readline ();
}

Static list <customers> customsort (list <customers> list, string [] citys)
{
List <customers> result = new list <customers> ();
Foreach (VAR item in citys)
{
VaR query = From S1 in list where s1.city = item select S1;
Foreach (VAR ditem in query)
Result. Add (ditem );
}
Return result;
}
}
}

 

VB. NET

 

Module module1

Sub main ()

Dim context as new dataclasses1datacontext ()

Dim lists = From S1 in context. Customers where (new string () {"UK", "Lisboa"}). Contains (s1.city) Select S1
For each item in customsort (lists. tolist (), new string () {"UK", "Lisboa "})
Console. writeline (item. City)
Next
Console. Readline ()
End sub

Function customsort (byval source as List (of MERs mers), byval citys as string ())
Dim result as new list (of MERs mers)
For each item in citys
Dim localitem = item
Dim query = From S1 in source where s1.city = localitem select S1
For each ditem in Query
Result. Add (ditem)
Next
Next
Return result
End Function

End Module

 

Please note that after the tolist is entered into zookeeper mode, the next msmsort will not send any SQL commands.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.