Last active
June 25, 2021 14:52
-
-
Save brianberns/af1daa39b50f380df59ed5ea98591ca4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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