LINQ to Object first experience (using object replace the two-dimensional array for data filtering)

VS2008 inside a magical thing called LINQ, can handle a variety of data through the same grammatical way (SQL, XML, Object, ...), a small meow this first experience to feel this thing , really well, first experience to be a simple test, look at the small of his right meow


VS2008 inside a magical thing called LINQ, can handle a variety of data through the same grammatical way (SQL, XML, Object, ...), a small meow this first experience to feel this thing , really well, first experience to be a simple test, look at the small of his right meow

First look at a map of LINQ architecture (Source: Cao teacher briefing in St. progenitor of TechEd2007)

Please select depends on complete drawing above, can be used to achieve considerable LINQ data from this chart, as long as the data can be used in the form of Object process, can be accessed through LINQ

Then began the first experience

First explain small meow do: meow get hold of the seat table, respectively --SeatId (seating Code), SeatName (seat name)
and then generate test data data 200 seats, SeatName (seat name) generates a random number az letters plus SeatId name as a seat, and finally a screen test using LINQ to filter data (look for the same prefix)

This topic before in ASP are small meow do with two-dimensional arrays in .NET which is the way the object can be used to replace two for an array

Object first establish a seat as follows:

Then set the following plan surface

 

Data generated on GridView1, the filtered data in GridView2

Write data is then generated portion

Then are our focus here, in these data, we want to find SeatName (seat name) at the beginning of a data before small meow may use cycles to check case by case basis, but with LINQ, it can be written in this way

We can see that with such short program will be able to do the screening. This is great

A friend familiar with T-SQL, you can imagine before then inside T-SQL inside Grou By, Distinct, Order By and so the object can then play, even through JOIN, the various objects associated with the data for later taking data. Really amazing ah.

这次的初体验只是约略的感受一下LINQ的威力,此次的例子只是两个字段,一个条件的筛选,各位可以试想一下,如果应用在很多字段,并且结合其他的数据(LINQ可以使用JOIN)并且使用多重条件的筛选,那么可以节省多少的程序就能够达到相同的目的。未来有其他的测试再与大家分享。

^_^


以下是签名:

  • 欢迎转贴本站的文章,不过请在贴文主旨上加上【转贴】,并在文章中附上本篇的超链接与站名【topcat姗舞之间的极度凝聚】,感恩大家的配合。
  • 小喵大部分的文章会以小喵熟悉的语言VB.NET撰写,如果您需要C#的Code,也许您可以试着用线上的工具进行转换,这里提供几个参考
    • http://converter.telerik.com/
    • http://www.carlosag.net/tools/codetranslator/
    • http://www.developerfusion.com/tools/convert/vb-to-csharp/

Microsoft MVP
Visual Studio and Development Technologies
(2005~Now)

topcat
Blog:http://www.dotblogs.com.tw/topcat


原文:大专栏  LINQ to Object初体验(使用对象取代二维数组作数据筛选)


Guess you like

Origin www.cnblogs.com/chinatrump/p/11490954.html