unidirectional association 1 to 1 not accpeted by EFc5 or EFDesigner
pas059 opened this issue · 23 comments
Hello,
I updated an app using Net 4.7.2 + EFc 3.1 to Net 5 + EFc 5; without asking EFDesigner to regenerate the files, everything run fine.
Today, i also updated EFDesinger to the latest version, and changed the 'Entity Framework Package Version' of my 'efmodel' to the '5.0.Latest'; this produces an error each time i have an 1 to 1 unidirectional association between en entity and a dependant entity. The error messages are like this one:
Organization.Address --> Address: The association from Address to Organization must be 1..0-1
Is this caused by a changes in EFc 5 that i did not saw or by the new version EFDesigner?
Regards
Unfortunately, EFCore5 doesn't yet support N-to-N unidirectional associations.
hi,
ok, but in my case this is not n to n, but 1 to 1. This is something that works with EFc 3.
Hi,
perhaps i not explained correctly the problem. I encounter this error, for 1 to 1 unidirectional association between en entity and a owned (dependant) entity. Fortunately, this kind of association is allowed by EFc 5 even if there is a litle improvement on this feature. For the 1 to 1 unidirectional associations between 2 entities, no error are signaled.
Regards
Thanks for the clarification. Using 3.0.2, I can't seem to reproduce the error (assuming I understand it correctly now). When I try the following
the designer accepts it and generates
modelBuilder.Entity<global::Sandbox_EFCore5NetCore3_Test.Entity1>().ToTable("Entity1").HasKey(t => t.Id);
modelBuilder.Entity<global::Sandbox_EFCore5NetCore3_Test.Entity1>().Property(t => t.Id).ValueGeneratedOnAdd().IsRequired();
modelBuilder.Entity<global::Sandbox_EFCore5NetCore3_Test.Entity1>().OwnsOne(p => p.Entity2).Property(p => p.SomeProperty).IsRequired();
modelBuilder.Entity<global::Sandbox_EFCore5NetCore3_Test.Entity1>().Navigation(p => p.Entity2).IsRequired();
modelBuilder.Owned<global::Sandbox_EFCore5NetCore3_Test.Entity2>();
and the subsequent migration is
migrationBuilder.CreateTable(
name: "Entity1",
schema: "dbo",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Entity2_SomeProperty = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Entity1", x => x.Id);
});
If you could make available a small model file showing the problem that would be really helpful in tracking this down.
Thanks.
Hello,
first of all, i wish you a happy new year.
I made a little project that recreates the issue. You can download it by following this link.
Regards
Thanks for the file, and a happy new year to you too! I was able to open the model and generate code without any issues. Possibly whatever was causing the problem was fixed by another change.
I'll close this for now and ask you to give it a try with the next release, which should be out today or later this weekend. If you still encounter problems, please feel free to reopen.
Hello,
I installed the latest version. Now this works when the selected 'Entity Framework package Version' is set to 'latest', but this does not work with others selections, even with 3.1.11.
regards
That's a limitation of the previous version.
See https://docs.microsoft.com/en-us/ef/core/modeling/owned-entities
In EF Core 3.x the columns for owned entity types mapped to the same table as the owner are always marked as nullable.
Hi,
i don(t think that this is the cause of the issue, because even when i select the 'Entity Framework package Version' as 5.0.latest, this not works.
This is a problem because using such '1 to 1' associations with the 'Entity Framework package Version' other than the 'latest' is not possible with EF-Designer v3, while this was possible without problems for instance with EF-Designer v2.0.5.7 targetting EFcore 3.1.x.
best regards
There is an issue with the designer and its mapping of capabilities to the selected EF version that's (hopefully) fixed in 3.0.4, the RC1 being available at https://github.com/msawczyn/EFDesigner/raw/master/dist/Sawczyn.EFDesigner.EFModel.DslPackage.vsix
If you could give that file a try, I'd be in your debt.
Hello,
i installed this version (3.0.4.5), but now i can not display the properties of the model, and so i could not change the EFc target, so i reinstalled the v3.0.3.2.
Nevertheless, i just noticed, that when "Entity Framework Version" is "EFCore", the field "Entity Framework package Version" could be 6.0.0 (??? I didn't even know it existed). So i imagine that when i select "Entity Framework package Version" as "latest" this the version 6 and not 5!
Someone can tell to microsoft to stop announce a new major version while the current version is not already stable.
best regards
LOL. No fear. While the Nuget package for v6 exists, and therefore is detected by the designer and shown in the property selector, there is currently no support for anything new in v6 for code generation or new features.
I am concerned, however by your report of but now i can not display the properties of the model
. That's nothing neither I've seen nor any other user has encountered. Do you mean that, when opening an .efmodel file it doesn't open, or when you get it open you can't select anything (including the design surface) and get the property window to display that selection's properties?
@pas059 - we need to diagnose this by process of elimination. Let's try something, if you're willing.
Create a new model file in that or some other project. Can you view/edit the designer surface properties there?
If yes, would you be able to get me a copy of the model file where you can't view those properties so that I can try to open it? If it's an error in the model file, I may be able to fix that for you.
If you still can't view those properties on a new model, grab one of the models in the testing solution (under https://github.com/msawczyn/EFDesigner/tree/master/src/Testing) and try it. Those work fine for me.
Hello,
sorry to reply late.
Now my devlopment environnement is VS2019CE Vers 16.8.6 and EFDesigner 3.0.4.7.
This changes nothing. I tried with the testing project EFCore5Net5, and this makes the same thing. I can open and display the model, display the properties of the entitie, but not the properties of the model.
An idea?
best regards
hello again,
i lso tried to create a new model, ... the same result.
best regards
Hello,
As i wondered where are defined these properties that EFDesigner does nt display, and assuming that they are defined in the .efmodel file, i displayed the .efmodel files with a xml editor and i noticed that some attributes of the 'modelRoot' element are missing; they are: entityFrameworkVersion and entityFrameworkPackageVersion. But even after added these atributes by comparison from a backup file, EFDesigner still does not display the properties.
If this can help
Best regards
I'm trying to get back in the swing of things again ... was this ever resolved? I see it's tagged as Released, so I'm guessing it was, although I don't want to close it without confirmation.
Hi,
now my devlopment environnement is VS2019CE Vers 16.9.4 and EFDesigner 3.0.4.7.
The situation is worse. For some project, it not possible to get/edit the model's properties as explain above, and for others when trying to open the model i've got an error : "le format de la chaine d'entrée est incorrect" which can be translated by "the format of the input string is incorrect ".
In both cases, this makes EFDesigner unusable. No emergency for my current app which does not changes from the DB point of view, but very soon i'd like to migrate to EFc5 (6?) ....
Regards
i noticed that some attributes of the 'modelRoot' element are missing
If a property is the same as the default, as defined in the DSL code, it's not written to the XML file, so you won't see it there.
We need to divide this problem up and start eliminating possibilities. Would you be willing to send me a file you can't open correctly? I'll see what it does on my computer.
Hi,
I just updated to EF Designer 3.0.5.2 and this works, i can open the models that i could no longer open, and now i can see and change the properties of the models. Then, i also updated to VS 2019CE 16.9.5 and this continue to work. Yeah!!
Regards