วันอังคารที่ 24 มีนาคม พ.ศ. 2558

Linq OrderBy Extension

ในการพัฒนาโปรแกรม ด้วย ASP.net ต้องมีการQuery ข้อมูลมาแสดงในGridView ซึ่งต้องมีส่วนของการ Sort Data แน่นอน และถ้าเราใช้ LinQ ละ? ผมจึงนำ Extension Method ใน LinQ นำมาฝาก
รูปแบบการเรียกใช้งานทำได้ดังนี้


list.OrderBy("SomeProperty");
list.OrderBy("SomeProperty DESC");
list.OrderBy("SomeProperty DESC, SomeOtherProperty");
list.OrderBy("SomeSubObject.SomeProperty ASC, SomeOtherProperty DESC");

 ที่มา
Dynamic SQL-like Linq OrderBy Extension
http://aonnull.blogspot.com/2010/08/dynamic-sql-like-linq-orderby-extension.html


C#.net Convert To VB.net By :http://converter.telerik.com/


View Code