Comments (14)
Some issues with scaffolding
- Do we create types as record types or as class types?
- I think that creating a type per file would not scale well as we would then have to figure out the dependencies between types to ensure they are compiled in the correct order.
- I would suggest that all types would be scaffolded into one recursive module so they can reference each other without issue
from efcore.fsharp.
Can F# record types be exposed to another C# library? If not I think it would be useful to define the EF Models as class types.
As for the ordering of files, I don't think we have a choice. While it might be bad database design, it is still possible for 2 tables in a database to reference each other, and our model would need to support that. This would required the and
keyword, which requires our types are in the same file.
from efcore.fsharp.
Yes, an F# record type is exposed to C# like below
type Person = { Name: string; Age: int }
is exposed as a sealed class with a constructor like
public Person(string name, int age)
F# 4.1 introduced recursive modules so we can declare something like module rec Domain
and all the types in it can reference each other without needing the and
keyword
from efcore.fsharp.
I think that creating a type per file would not scale well
I'm going to reworking some of the RevEng interfaces for EF Core 2.1, I'll keep in mind that generators may want to put everything into a single file.
from efcore.fsharp.
cc @cartermp (FYI so you can track F# support for this in EF Core)
from efcore.fsharp.
You may use the C# version as a reference implementation. See CSharpModelGenerator and its subcomponents CSharpDbContextGenerator and CSharpEntityTypeGenerator.
from efcore.fsharp.
Just my two cents. It's been a while since I used EF - if possible, I'd recommend trying to stick with the standard set of types that F# devs use:
- Records
- Immutable fields (although I suppose that all the fields on the record will need to be
mutable
to work with things like change tracking)? - If possible, discriminated unions for many-types-per-table style relationships (which would be modelled with inheritance in C#).
from efcore.fsharp.
Depending on interoperability requirements we can create types as either records or class types, maybe depending on an input parameter. This is the approach I'm taking at the moment
Although if interoperability between C# and F# projects is a requirement it would make just as much sense to use C# for EFCore...
Good thinking regarding DU's for many-types-per-table style relationships, hadn't considered these models before but a discriminated union definitely makes the most sense
from efcore.fsharp.
Where is the reverse engineering implementation at? Can we put an alpha of it up on NuGet.org yet?
from efcore.fsharp.
Haven't worked on reverse engineer support in a while so will have to double check later when I get a chance but if it's not good for alpha it shouldn't take long to get it there
from efcore.fsharp.
@bricelam
Looking into this at the moment and getting this error
Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Scaffolding.ProviderCodeGenerator' while attempting to activate 'Bricelam.EntityFrameworkCore.FSharp.Scaffolding.FSharpDbContextGenerator'
This is testing using Postgresql, a C# project performs the scaffold correctly
The issue appears to be here
https://github.com/aspnet/EntityFrameworkCore/blob/release/2.2/src/EFCore.Design/Design/Internal/DesignTimeServicesBuilder.cs#L89
Am I correct that currently EF Core will only load one instance of IDesignTimeServices
?
from efcore.fsharp.
One from the user’s startup assembly. There can be multiple registered via DesignTimeServicesReferenceAttribute. The msbuild script adds this attribute to the startup project.
from efcore.fsharp.
Was able to scaffold the Northwind database without issue
At this stage I feel an alpha release can be justified
Caveats
#20 - generated files are not added to the project by default
#21 - many-types-per-table relationships are not currently supported
While #20 would not necessarily block an alpha release it is definitely something to be addressed soon as it is a major usability issue. We should not have to leave it up to the user to figure out the compilation order
Have created #23 to merge these changes
from efcore.fsharp.
Initial support added
Everything from here on will be a new ticket
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.