Skip to content

Instantly share code, notes, and snippets.

Last active April 6, 2020 07:32
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Using EF Core with CosmosDB in F#
open System
open Microsoft.EntityFrameworkCore
type [<CLIMutable>] LegacyForm = {
id: string // The form's UID.
Client: string
CompanyId: int
Number: string
InstallationAddress: string
Status: string
Type: string
Uid: string
ModelVersion: string
LastUpdatedUtc: DateTime
type LegacyFormsContext =
inherit DbContext
(* Based on Eelco Mulder's repo here: *)
new() = { inherit DbContext() }
new(options: DbContextOptions<LegacyFormsContext>) = { inherit DbContext(options) }
override __.OnConfiguring (optionsBuilder: DbContextOptionsBuilder) =
"MyDB") |> ignore
override __.OnModelCreating modelBuilder =
|> ignore
val mutable forms:DbSet<LegacyForm>
member x.Forms
with get() = x.forms
and set v = x.forms <- v
module LegacyFormsRepo =
let formById (context: LegacyFormsContext) id =
query {
for form in context.Forms do
where ( = id)
select form
} |> (fun x -> if box x = null then None else Some x)
let formsForCompany (context: LegacyFormsContext) companyId =
query {
for form in context.Forms do
where (form.CompanyId = companyId)
select form
skip 4
take 2
} |> Array.ofSeq
let main argv =
let context = new LegacyFormsContext()
let formId = "ec770405-692d-44cf-a5a7-0c0fd7ca1f3f"
let form = LegacyFormsRepo.formById context formId
let forms = LegacyFormsRepo.formsForCompany context 123
forms |> printfn "%A"
Console.Read() |> ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment