Comments (5)
This is quite challenging, for a few obvious reasons and some more subtle:
- Order of files matters in F#. E.g. these migrations need to be inserted below the declaration of the
DbContext
. - There's no easy way of knowing the source file containing the
DbContext
or if it is the correctDbContext
. - There could be multiple .fsproj files in a single directory.
- Any solution needs to work cross platform which leads onto:
- There doesn't appear to be an easy API for dotnet core to manipulate .fsproj files (Although there is for .NET framework). I may be wrong here?
Having said that, I have attempted this on my fork, you can see the code here: https://github.com/DurdSoft/EFCore.FSharp/blob/db135cf8c8b44891c2281eeb3e94c9276493adb2/src/EFCore.FSharp/Migrations/Design/FSharpMigrationsScaffolder.fs#L62
It relies heavily on string matches and there would no doubt be scenarios that could cause it to trip up.
I'd be interested to see what you think @isaacabraham - you probably have more experience of complex .fsproj
files than me - I only F# for a hobby! I've no doubt missed some potential gotchas.
Worth noting there was a previous discussion on this here: #20 but it didn't pick up much steam.
from efcore.fsharp.
@DurdSoft few quick notes after briefly looking at your fork. First off, great job knocking out these getting-started issues!
- I'd look at using
dotnet-proj-info
for 'project file cracking', aka finding out information about the structure and contents of a project file. It's used in several other projects that need information about this and is sorta the go-to for consistent, correct results. It defers to msbuild under the covers so it is consistent with what the rest of the build system sees - have you thought about enforcing a certain structure on users of EFCore.FSharp? It's definitely possible to have limited glob-includes of f# files based on patterns, so if you required a user to have a fsproj item like
<Compile Include="Migrations/*.fs" />
you could then generate strictly-ordered migrations (perhaps by use of a formatted timestamp) and they would be correctly-ordered as long as they appear in a Migrations folder after the DbContexts have been defined.- I do this in my work projects that use FluentMigrator along with a quick helper script to template out a new migration and it works great!
from efcore.fsharp.
Thank you for the link to that project, that would certainly help us with the file schema. Certainly we could look at how Ionide manages this. I'm not sure about enforcing a structure - EF is already very opinionated!
However, that still leaves a few issues I can think of off the top of my head that make a holistic solution difficult:
- We don't know the file containing the derived
DbContext
. It seems the compiler doesn't know much about correcting file order (or we would get hints when the project cannot compile due to order - perhaps a naive assumption?) so we'd always have to speculate. Maybe could look at generated.pdb
files? - Multiple
.fsproj
files in a single directory (which one should be updated?) - Identifying whether we're adding the first migration or a subsequent one - don't want to add a file twice.
I'm not 100% sure how this works with C#, .NET Framework and EF Core. If I remember correct, the .csproj
file for Framework requires files to be listed. It's probably worth doing some investigation there as well.
from efcore.fsharp.
I think @baronfel idea re: globbed folder is the way to go. Worst case it's a one-off move of the folder in the project hierarchy the first time and after this it'll just work.
from efcore.fsharp.
Migrations are created with a timestamp in the filename as is so they would be automatically sorted correctly with globbing
I think that could be the best approach alright
from efcore.fsharp.
Related Issues (20)
- [Single case DUs] The binary operator Equal is not defined for the types `UserId` and `UserId` HOT 1
- DbContextHelpers.fs methods return type obj instead of 'a HOT 1
- [Option] Optional DateTime properties cannot be filtered HOT 1
- Migration not generated due to optional single case DU HOT 1
- Unable to create migration using Pomelo's connector when Option types are already present in model HOT 7
- How do you create an optional navigation property? HOT 3
- Scaffolding fails if a column uses a DEFAULT value
- singleCaseUnionMemberTranslator Translate should return null for non-applicable expressions
- Support for empty discriminated union HOT 2
- Documentation: Guide on how to create a many-to-many relationships HOT 2
- When trying to call registerSingleCaseUnionTypes from C#, I get an InvalidOperationException
- NullReferenceException on second migration HOT 1
- The Getting Started guide does not work well HOT 3
- NullReferenceException when deleting optional fields
- Support EF Core 7 HOT 1
- Scaffolding a `nvarchar NULL` creates a `string` and not a `string option`
- Nullpointer on second migration when having a string option field
- Extension UseFsharpTypes() interferes with the npgsql translation for where statement on jsonb columns
- Subsequent migrations fail with `type 'JsonDocument' is not defined` error for JSONB column HOT 3
- Npgsql JSONB to POCO mapping produces an empty `open` stmt in `Migration/*Snapshot.fs`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from efcore.fsharp.