有没有办法在使用F#LINQ到SQL查询表达式时进行动态排序 - 在C#中使用动态LINQ。特别是我希望做到以下几点,
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
}
答案 0 :(得分:1)
DynamicLinq是使用Extension方法实现的,那些应该在F#3.0中工作,那么为什么不像在C#中那样使用DynamicLinq?
open System.Linq.Dynamic
...
let db = schema.GetDataContext()
db.Student.OrderBy("Name")