2014-01-19 49 views
1

當使用F#LINQ to SQL查詢表達式時,有沒有辦法在C#中進行動態排序 - ala dyanmic LINQ?特別是我期待做到以下幾點,如何在F#LINQ to SQL中動態排序

open System 
open Microsoft.FSharp.Data.TypeProviders 
open System.Data.Linq.SqlClient 
open System.Linq 
open Microsoft.FSharp.Linq 

type schema = SqlDataConnection<"Data Source=SERVER\INSTANCE;InitialCatalog=MyDatabase;Integrated Security=SSPI;"> 

let db = schema.GetDataContext() 
query { 
    for student in db.Student do 
    sortBy "Name" //provide column name as string rather than expr 
    select student 
} 

回答

1

DynamicLinq與擴展方法實現的,這些應該在F#3.0工作,所以爲什麼不使用DynamicLinq就像您在C#中?

open System.Linq.Dynamic 

...

let db = schema.GetDataContext() 
db.Student.OrderBy("Name")