Note that there are some explanatory texts on larger screens.

plurals
  1. POF# WebApi using record types doesn't give the desired XML output
    primarykey
    data
    text
    <p><strong>The working code is at the bottom of this question!</strong></p> <p><strong>With the following WebApi controller in F#:</strong></p> <pre><code>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&lt;"conn string"&gt; [&lt;CLIMutable&gt;] type ViewModelRec = { CustomerId : string } type ValuesController() = inherit ApiController() let db = dbSchema.GetDataContext() do db.DataContext.Log &lt;- 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() } } </code></pre> <p><strong>The XML output is:</strong></p> <pre class="lang-xml prettyprint-override"><code>&lt;ArrayOfViewModelRec xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/FsWeb.Controllers"&gt; &lt;ViewModelRec&gt; &lt;CustomerId_x0040_&gt;A98971F0-5F93-4F0D-B5AC-95E161458381&lt;/CustomerId_x0040_&gt; &lt;/ViewModelRec&gt; &lt;ViewModelRec&gt; &lt;CustomerId_x0040_&gt;60DF7CF6-91FB-4BBE-AD6B-FE0CAA32F60E&lt;/CustomerId_x0040_&gt; &lt;/ViewModelRec&gt; &lt;ViewModelRec&gt; &lt;CustomerId_x0040_&gt;84506E40-139C-4DD1-B396-3CE13DC20996&lt;/CustomerId_x0040_&gt; &lt;/ViewModelRec&gt; &lt;ViewModelRec&gt; &lt;CustomerId_x0040_&gt;D9FABC12-9B19-46C2-9776-E31171A302D5&lt;/CustomerId_x0040_&gt; &lt;/ViewModelRec&gt; &lt;ViewModelRec&gt; &lt;CustomerId_x0040_&gt;B1B6C617-AA0E-46A9-A0B6-312A229BE178&lt;/CustomerId_x0040_&gt; &lt;/ViewModelRec&gt; &lt;ViewModelRec&gt; &lt;CustomerId_x0040_&gt;BAB194AE-CD2C-400F-B81E-2A293C50C404&lt;/CustomerId_x0040_&gt; &lt;/ViewModelRec&gt; &lt;ViewModelRec&gt; &lt;CustomerId_x0040_&gt;AE001AB4-8410-43BF-9C93-AE5A2EACFDF5&lt;/CustomerId_x0040_&gt; &lt;/ViewModelRec&gt; &lt;ViewModelRec&gt; &lt;CustomerId_x0040_&gt;2DDBDB91-9307-4BF7-865F-C6237D09D542&lt;/CustomerId_x0040_&gt; &lt;/ViewModelRec&gt; &lt;ViewModelRec&gt; &lt;CustomerId_x0040_&gt;A3E93E5C-2B7E-4B8D-8AAD-AD245E32093F&lt;/CustomerId_x0040_&gt; &lt;/ViewModelRec&gt; &lt;ViewModelRec&gt; &lt;CustomerId_x0040_&gt;B64B814F-9B4C-46BD-A804-648309FA7DD0&lt;/CustomerId_x0040_&gt; &lt;/ViewModelRec&gt; &lt;/ArrayOfViewModelRec&gt; </code></pre> <p>When I use a class instead, the naming looks correct (without the <em>x0040</em> tag).</p> <p>Anyone a suggestion?</p> <p><strong>Updated: Solution:</strong></p> <pre><code>namespace FsWeb.Controllers open System.Web open System.Web.Mvc open System.Net.Http open System.Web.Http open System.Runtime.Serialization; open Microsoft.FSharp.Linq; open Microsoft.FSharp.Data.TypeProviders; type dbSchema = SqlDataConnection&lt;"here comes the connection string"&gt; [&lt;DataContract&gt;] type ViewModelRec = { [&lt;field: DataMember(Name="CustomerId")&gt;] CustomerId : string } type ValuesController() = inherit ApiController() let db = dbSchema.GetDataContext() do db.DataContext.Log &lt;- System.Console.Out 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() } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload