Skip to content

Instantly share code, notes, and snippets.

@brianberns
Last active June 25, 2021 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianberns/af1daa39b50f380df59ed5ea98591ca4 to your computer and use it in GitHub Desktop.
Save brianberns/af1daa39b50f380df59ed5ea98591ca4 to your computer and use it in GitHub Desktop.
open Microsoft.EntityFrameworkCore
[<CLIMutable>]
type Customer =
{
CustomerId : string
CompanyName : string
Address : string
City : string
}
type CustomerDataContext() =
inherit DbContext()
[<DefaultValue>]
val mutable customers : DbSet<Customer>
member public this.Customers
with get() = this.customers
and set(value) = this.customers <- value
override __.OnConfiguring(optionsBuilder : DbContextOptionsBuilder) =
optionsBuilder
.UseSqlServer("Server=localhost;Database=Northwind;Trusted_Connection=True;")
|> ignore
module Customer =
let getCustomers (ctx : CustomerDataContext) =
ctx.Customers
.ToArrayAsync()
|> Async.AwaitTask
[<EntryPoint>]
let main argv =
let ctx = new CustomerDataContext()
Customer.getCustomers ctx
|> Async.RunSynchronously
|> Seq.iter (printfn "%A")
0
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<WarnOn>3390;$(WarnOn)</WarnOn>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.7" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="5.0.2" />
</ItemGroup>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment