工作代码是这个问题的底部!
使用F#中的以下WebApi控制器:
namespace FsWeb.Controllers
open System.Web
open System.Web.Mvc
open System.Net.Http
open System.Web.Http
open Microsoft.FSharp.Linq;
open Microsoft.FSharp.Data.TypeProviders;
type dbSchema = SqlDataConnection<"conn string">
[<CLIMutable>]
type ViewModelRec = { CustomerId : string }
type ValuesController() =
inherit ApiController()
let db = dbSchema.GetDataContext()
do
db.DataContext.Log <- System.Console.Out
// GET /api/values
member x.Get(take:int, skip:int) =
let t = take
let s = skip
query {
for row in db.Reservations do
skip s
take t
select { CustomerId = row.CustomerId.ToString() }
}
Run Code Online (Sandbox Code Playgroud)
XML输出是:
<ArrayOfViewModelRec xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/FsWeb.Controllers"> …Run Code Online (Sandbox Code Playgroud)