+ /// Fsdocs.build (fun p -> { p with Clean = Some(true); Strict = Some(true) })
+ ///
+ ///
+ /// Fsdocs.watch (fun p -> { p with Port = Some(3005) })
+ ///
+ /// Every introduction to .NET Core onwards will usually start by suggesting EntityFramework Core as the go-to choice for data access.
-Unfortunately EF Core will output all generated code in C# and C# alone. While it is the most popular .NET language, it it not the only .NET language.
-This project brings support for F# to EF Core, allowing for database scaffolding, migrations to be created in F#.
-If that's what you want to use, please do! The sheer scale of database access libraries in .NET and in F# is one of the great strengths of the community.
-But as EF Core is one of the most widely known ORM solutions in the .NET world, it makes sense that it should support various .NET languages. That's what this project is for.
-EF Core by default does not know anything about the way of F# deals with nullable values which is the Option type.
-This project has a way to enable query for columns defined as an option, first you need to call .UseFSharpTypes() on the
-context configuration builder
1: - 2: - 3: - 4: - 5: - 6: - 7: - 8: - 9: -10: -11: -12: -13: -14: -15: -16: -17: -18: -19: -20: -21: -22: -23: -24: - |
- |
-
Note that the .UseFSharpTypes() will exist independent of the database, the UseSqlite is just for the example.
-If you are using an SQL server with UseSqlServer or UsePostgres for Postgres, or any other database it will exist.
With that, you will be able to query your entity by an optional column.
-Querying entities with Some content
1: - 2: - 3: - 4: - 5: - 6: - 7: - 8: - 9: -10: -11: -12: -13: -14: -15: - |
- |
-
Querying entities with None content
1: - 2: - 3: - 4: - 5: - 6: - 7: - 8: - 9: -10: -11: -12: -13: -14: - |
- |
-
Querying optional values by value
-1: - 2: - 3: - 4: - 5: - 6: - 7: - 8: - 9: -10: -11: -12: -13: -14: - |
- |
-
EF Core allows us to scaffold a model in code, based on an existing database.
-Because F# allows multiple ways of representing an object, we are able to provide configuration options for how that generated code is formed.
-If we wanted to model a blog post with an Id, Title and Content we could do it as a record type
-1: -2: -3: -4: -5: - |
- |
-
Or we could do it as a class type, that would behave more like how a C# class would
-1: - 2: - 3: - 4: - 5: - 6: - 7: - 8: - 9: -10: - |
- |
-
Similarly, if we had a nullable column, for instance of type Guid, it might be specified as either Nullable<Guid> or in more idiomatic F#, as guid option
Again, we provide options for how these should be scaffolded.
-We provide EntityFramework.FSharp.ScaffoldOptions to specify how we want to create our scaffolded code.
By default we scaffold record types with nullable columns represented as option types, but this can be overridden.
To do this, you'll need your own implementation of IDesignTimeServices, where we can declare a ScaffoldOptions object.
The ScaffoldOptions.Default object is equivalent to ScaffoldOptions (ScaffoldTypesAs = RecordType, ScaffoldNullableColumnsAs = OptionTypes)
If you are happy with the default of record-type objects with option properties then you will not need to implement this at all, it is already handled automatically for you.
1: - 2: - 3: - 4: - 5: - 6: - 7: - 8: - 9: -10: -11: -12: -13: -14: -15: -16: -17: -18: -19: -20: -21: -22: -23: - |
- |
-
EFCore.FSharp also includes a number of helper methods for allowing a more F#-like experience while interacting with a DbContext.
They can be found in EntityFrameworkCore.FSharp.DbContextHelpers
Given a context with a Blog defined as such
1: - 2: - 3: - 4: - 5: - 6: - 7: - 8: - 9: -10: -11: -12: -13: -14: - |
- |
-
We can use the helper methods like so
-1: - 2: - 3: - 4: - 5: - 6: - 7: - 8: - 9: -10: -11: -12: -13: -14: -15: -16: -17: -18: -19: -20: -21: -22: -23: -24: -25: -26: -27: -28: -29: -30: - |
- |
-
An advantage of the generalised updateEntity function is that it allows us to use partial application to easily create methods for specific entities. For example:
1: -2: -3: -4: -5: -6: -7: -8: -9: - |
- |
-
We also have methods and functions for DbSet/IQueryable to replace usage of FirstOrDefault and FirstOrDefaultAsync:
1: - 2: - 3: - 4: - 5: - 6: - 7: - 8: - 9: -10: -11: -12: -13: -14: -15: -16: -17: -18: -19: -20: -21: -22: -23: -24: -25: -26: -27: -28: -29: -30: -31: -32: -33: -34: - |
- |
-
All methods in EntityFrameworkCore.FSharp.DbContextHelpers also have Async variants with support for async { ... } expressions
It's common to use single case discriminated unions to meaningfully represent data values. -But EF does not know anything about this kind of type. Luckily this repository has some ways to help you to deal with they.
-We have two approaches to deal with single case union types which are a converter or an extension that searches for all Single Case Unions in your entities.
-1: - 2: - 3: - 4: - 5: - 6: - 7: - 8: - 9: -10: -11: -12: -13: -14: -15: -16: -17: -18: -19: -20: -21: -22: -23: -24: -25: -26: -27: -28: -29: -30: -31: -32: -33: -34: -35: -36: -37: - |
- |
-
You can query for equality without any problem
-1: - 2: - 3: - 4: - 5: - 6: - 7: - 8: - 9: -10: - |
- |
-
For querying with other types of operation you will need to unwrap the value inside the query
-1: -2: -3: -4: -5: -6: -7: -8: - |
- |
-
This extension doesn't support private union case constructors.
-This guide assumes:
-dotnet-ef toolpaket
-1:
- |
- |
dotnet CLI
-1:
- |
- |
Yes, really. Standard EF Core commands such as dotnet ef migrations add and dotnet ef dbcontext scaffold will now work as usual but the generated code will be in F#
The necessary design time services are automatically registered by EntityFrameworkCore.FSharp. Unless you have a specific need to do so, you should not need to register your own implementation of IDesignTimeServices just to add F# support.
An example of where you would need to, would be if you were scaffolding a new context from an existing database.
-By default, scaffolded objects will be created as Record types objects where nullable columns of type 'a are represented as types of 'a option.
If you want to change the deault behaviour to generate nullable columns as properties of type Nullable<'a> or to crete your entities as a C#-type class object, check out Scaffolding Types
place images or other files here
-EFCore.FSharp provides F# design time support for EF Core.
-EF Core is the default option for data access that most people with experience in .NET are aware of. It should be possible to use any .NET language with it, not just C#
-This provides support for code-first and database-first use of EF Core in F#, including supporting record and option types.
-The basics of getting started with EFCore.FSharp.
-Guides you through the steps involved in addressing key problems and use-cases.
-Discusses key topics and concepts at a fairly high level and provide useful background information and explanation..
-Contain technical reference for APIs.
-The basics of getting started with EFCore.FSharp.
@@ -33,11 +33,11 @@ This provides support for code-first and database-first use of EF Core in F#, inGuides you through the steps involved in addressing key problems and use-cases.
@@ -48,7 +48,7 @@ This provides support for code-first and database-first use of EF Core in F#, inDiscusses key topics and concepts at a fairly high level and provide useful background information and explanation..
@@ -59,7 +59,7 @@ This provides support for code-first and database-first use of EF Core in F#, inContain technical reference for APIs.
diff --git a/docsTool/CLI.fs b/docsTool/CLI.fs deleted file mode 100644 index 1864267..0000000 --- a/docsTool/CLI.fs +++ /dev/null @@ -1,48 +0,0 @@ -namespace DocsTool - -module CLIArgs = - open Argu - open Fake.IO.Globbing.Operators - - type WatchArgs = - | ProjectGlob of string - | DocsSourceDirectory of string - | GitHubRepoUrl of string - | ProjectName of string - | ReleaseVersion of string - interface IArgParserTemplate with - member this.Usage = - match this with - | ProjectGlob _ -> "The glob for the dlls to generate API documentation." - | DocsSourceDirectory _ -> "The docs source directory." - | GitHubRepoUrl _ -> "The GitHub repository url." - | ProjectName _ -> "The project name." - | ReleaseVersion _ -> "The project's Release Version name." - - type BuildArgs = - | SiteBaseUrl of string - | ProjectGlob of string - | DocsOutputDirectory of string - | DocsSourceDirectory of string - | GitHubRepoUrl of string - | ProjectName of string - | ReleaseVersion of string - interface IArgParserTemplate with - member this.Usage = - match this with - | SiteBaseUrl _ -> "The public site's base url." - | ProjectGlob _ -> "The glob for the dlls to generate API documentation" - | DocsOutputDirectory _ -> "The docs output directory." - | DocsSourceDirectory _ -> "The docs source directory." - | GitHubRepoUrl _ -> "The GitHub repository url." - | ProjectName _ -> "The project name." - | ReleaseVersion _ -> "The project's Release Version name." - - type CLIArguments = - | [