Skip to content

Instantly share code, notes, and snippets.

@jjvdangelo
Last active August 29, 2015 13:57
Show Gist options
  • Save jjvdangelo/9383142 to your computer and use it in GitHub Desktop.
Save jjvdangelo/9383142 to your computer and use it in GitHub Desktop.
// --Snip--
let getEntity id =
use conn = EntityContext.GetDataContext()
query { for t1 in conn.Table_1 do
join t2 in conn.Table_2 on (t1.id = t2.table_1_id)
where (t1.id = id)
select t2
headOrDefault } |> function
| null -> Unchecked.defaultof<_>
| t2 -> { Id = t2.id; Value = t2.value }
interface IGet with
member this.Get() =
this.Result <- this.Id |> getEntity
match this.Result = Unchecked.defaultof<_> with
| true -> Status 413
| false -> Status 200
namespace BlowingUpSqlEntityConnection.Web
open Simple.Web
open BlowingUpSqlEntityConnection.Web.Data
type Result = { Id: int; Value: int }
[<UriTemplate("/foo/{Id}/bars")>]
type Index() as this =
let getEntity() =
use conn = EntityContext.GetDataContext()
query { for t1 in conn.Table_1 do
join t2 in conn.Table_2 on (t1.id = t2.table_1_id)
where (t1.id = this.Id)
select t2
headOrDefault } |> function
| null -> Unchecked.defaultof<_>
| t2 -> { Id = t2.id; Value = t2.value }
member val Id = null with get, set
member val Result = Unchecked.defaultof<_> with get, set
interface IGet with
member this.Get() =
this.Result <- getEntity()
match this.Result = Unchecked.defaultof<_> with
| true -> Status 413
| false -> Status 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment