Comments (18)
Hi, support is planned, and slowly in progress
I've created a branch https://github.com/efcore/EFCore.FSharp/tree/net5.0 that targets the latest version of EF Core (5.0.3)
So far it's just getting everything targeting NET 5.0, I've handled the Type.GetNamespaces()
API change but everything else is still in progress.
@DurdSoft, thanks for the list above, I'm happy to work through them with you and hopefully we can actually get a release out
from efcore.fsharp.
@simon-reynolds I've added @DurdSoft and made you an admin.
Copying/porting Multigraph into this project is the right thing to do.
from efcore.fsharp.
There's a series of API changes from 3.1.x -> 5.x that'll need to be figured out:
// Removed
IAnnotationCodeGenerator.IsHandledByConvention
IAnnotationCodeGenerator.GenerateFluentApi
CoreAnnotationNames.TypeMapping
CoreAnnotationNames.ChangeTrackingStrategy
ChangeDetector.SkipDetectChangesAnnotation
Microsoft.EntityFrameworkCore.Internal.TypeExtensions.GetNamespaces
Type.DisplayName
Multigraph<T>
IEntityType.IsIgnoredByMigrations()
Type.GetNamespaces()
//Changed
IProperty.IsFixedLength() // bool to Nullable<bool>
ICSharpDbContextGenerator.WriteCode // changed signature
INavigation.IsCollection() // changed from method to property
(also I'm getting a stackoverflow problem with paket)
It shouldn't be a huge job. The code structure roughly follows the C# implementation so it should be a case of side-by-siding and figuring out how the API has changed.
As there has never been a nuget release it would seem to make sense to shift to the latest packages. I'll have a look at it sometime this week.
from efcore.fsharp.
I think the 2 main pain points will be:
- Annotations - some have been removed, others deprecated. I'm not sure if there's a reason why we didn't or don't just use
IAnnotationCodeGenerator
and the DB specific implementations in EF Core? This would putFSharpMigrationsGenerator
andFSharpDbContextGenerator
on a diet. Multigraph<T>
has been made internal. This seems to be important in making sure the snapshots are generated in a logical order. I'm not sure what the best way forward here would be.
from efcore.fsharp.
Because when I first started working on this back in the 2.x days, IAnnotationCodeGenerator
didn't exist 😄
I'm currently working through FSharpDbContextGenerator
at the moment and yeah, it's definitely going to be losing a lot of complexity
Trying to figure out the best way to handle Multigraph<T>
, shall have to see what we can come up with
Maybe something that @bricelam may have some ideas on if he has a chance to take a look?
from efcore.fsharp.
That makes sense! I've built off your branch some more of the required code changes here. 2 of the unit tests are failing and I've side stepped the Multigraph<T>
issue.
from efcore.fsharp.
Perfect! Can you create a PR for that please?
Getting as far as unit tests running in order to fail means you're ahead of me 😀
from efcore.fsharp.
I've updated my branch to fix the tests. Most the work is done to migrate to AnnotationCodeGenerator
.
There's a failing test still - the one related to snapshot enum generation that was commented out. I think there's a genuine issue here. The C# generation up to the point where c.ConvertToProvider.Invoke(defaultValue)
is called looks like:
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations.Design;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace MyNamespace
{
[DbContext(typeof(CSharpMigrationsGeneratorTest.MyContext))]
partial class MySnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGeneratorTest+WithAnnotations", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("default_int_mapping");
b.Property<int>("EnumDiscriminator")
.HasColumnType("default_int_mapping");
b.HasKey("Id");
b.ToTable("WithAnnotations");
b.HasDiscriminator<int>("EnumDiscriminator")
Whereas the F# version:
namespace MyNamespace
open System
open EntityFrameworkCore.FSharp.Test.Migrations.Design
open Microsoft.EntityFrameworkCore
open Microsoft.EntityFrameworkCore.Infrastructure
open Microsoft.EntityFrameworkCore.Metadata
open Microsoft.EntityFrameworkCore.Migrations
open Microsoft.EntityFrameworkCore.Storage.ValueConversion
[<DbContext(typeof<MyContext>)>]
type MySnapshot() =
inherit ModelSnapshot()
override this.BuildModel(modelBuilder: ModelBuilder) =
modelBuilder.Entity("EntityFrameworkCore.FSharp.Test.Migrations.Design.Derived", (fun b ->
b.HasBaseType("EntityFrameworkCore.FSharp.Test.Migrations.Design.WithAnnotations")
b.HasDiscriminator()
This was probably broken in the code in 3.1 as well.
from efcore.fsharp.
That's some really great work! Can you create a PR again for these changes please?
@bricelam, whenever you get a chance to see this, can you add @DurdSoft as a collaborator to this repo?
from efcore.fsharp.
The issue was related to the missing Multigraph
and some misconfiguration in the test setup. I've added a slightly naive implementation of Multigraph
(until we can decide what we want to do with it) which is enough to get it over the line - I'll put in a PR 👍
from efcore.fsharp.
I've put in another PR for a silly mistake I'd made, sorry!
There are still a few outstanding issues in scaffolding:
-
Build is failing - not too sure what's changed on this ?
-
HasIndex
is failing now where it worked on 3.1. In this screenshot, it should be using theExpression<_>, string
overload but doesn't seem at all happy with it. I wonder if something changed in net 5.0 (or more likely, it's something way more obvious).
If either argument is removed it is happy again.
ToTable
is missing for modelBuilder entities on DbContext.
from efcore.fsharp.
I'm working my way through the DbContextGenerator
so I'll take care of ToTable
Looks like the compiler currently thinks the expression is supposed to a tuple of obj * string
so you should be able to get HasIndex
working if you put parentheses around the expression
.HasIndex((fun e -> e.EntityId :> obj), "exntity_id_idx")
from efcore.fsharp.
D'oh, of course. I'm going to look into migrating more of the unit tests so we can get it 1 to 1 with C#. I'm surprised none of the existing ones have caught that missing ToTable(...)
call - and there'll probably be similar bits like that in their as well.
from efcore.fsharp.
Cool, I'm going to look at tidying up the implementations in Snapshot, DbContext and Migration generators so bring them more in line with the changes in EFCore for net5.0
from efcore.fsharp.
Hi @DurdSoft
The enum test now passes, if we can add more tests to bring to parity with C# that would be great
from efcore.fsharp.
I tested the net5.0 branch. Migrations seems to created ok, but have a few minor issues.
Two opens missing:
open Microsoft.EntityFrameworkCore.Migrations.Operations.Builders
open Microsoft.EntityFrameworkCore.Migrations.Operations
Some syntax errors:
- Two commas after name in
CreateTable
- Fields have comma missing between nullable and type, and an extra comma after type
- Fields have extra comma at the end
table.ForeignKey
, migrationBuilder.DropTable
and migrationBuilder.CreateIndex
have also an extra comma at the end
table.Foreignkey
is missing newline and comma after column
:
With these changes I was able to migrate our database, great work!
from efcore.fsharp.
Hi @tomiaijo
Thank you so much for the feedback and the kind words
I'll see what I can do about these issues and hopefully we'll then be in a good enough state to be able to release a NuGet package
from efcore.fsharp.
Hi @tomiaijo,
Can you try this with the latest commits on the net5.0 branch?
I just pushed a change to correct an issue affecting CreateTable operations
I couldn't see the issues you encountered though. I was able to create an example using basic MVC authentication at https://github.com/simon-reynolds/EFCore.FSharp.MvcAuth
Can you try with the latest versions and let me know if you're still having the same problems?
I've included the latest version of the nuget package at https://github.com/simon-reynolds/EFCore.FSharp.MvcAuth/tree/main/packages
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.