You could use Expression Splices (§6.9.3 in the spec):

1
2
3
4
let data = <@ seq { for i in context.MyTable do if i.Param > 10 then yield i } @>

<@ Seq.take 10 %data @> |> query |> Seq.toList
<@ Seq.take 3 %data @> |> query |> Seq.toList 

Regarding the formatting, see Brian's post.

By on 4/23/2010 3:17 AM ()

C# seems to have an advantage as it is more elegant(to me anyway) in this case.

My understand is that the whole 'quotation' would be passed through the 'transformation' process(turned into SQL statement) which is why the Seq.take needs to be in quotation as well.

Whereas for the C# situation, all the .Take .Where functions are in a sense 'monad binding' so it is just naturally deferred(each return of the function is just another monad, or in F#, quotation) and is finally transformed into SQL when the result are really needed.

By on 4/24/2010 12:16 PM ()

Yes, by using a dedicated query type (IQueryable), C#'s LINQ expressions are implicitly executed when enumerated. However, I don't really mind the explicit query call - some things should better remain explicit. And I certainly don't want to pay the angle-at bracket tax on

1
2
3
|> Queryable.map <@ fun order -> order.Company @>
|> Queryable.filter <@ fun company -> company.IsSolvent @>
|> Queryable.sortBy <@ fun company > company.Name @>

:)

By on 4/25/2010 3:23 AM ()

though in this case, the explicit is about some implementation detail which I don't see why it needs to be exposed.

May be the C# linq behaviour can be done in some form of monad(i.e. computational expression) like the following :

1
2
3
4
let q = linq { <@ .... @> }

q.Take(10).Filter(...)

where the Tak/Filter just compose another IQueryable

By on 4/25/2010 12:54 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper