-
Notifications
You must be signed in to change notification settings - Fork 60
Include on 1->n relation with EF core 5 doesn't work #254
Comments
Yes, I can subscribe to this issue: Looks like I can also reproduce this issue with EF Core 5.0.0. In case you need any further information from us on this, Michael, just let us know! |
Sorry to bother you, @michael-sawczyn, but did you have the chance to try that on your side? I'm just wondering if I'm doing something wrong as this is such basic functionality, so I would expect more reports about this issue actually. Thanks for support as always |
I've actually run across this in one of my projects as well. Am trying to track it down. Stay tuned! |
Great to hear that you can reproduce this as well, @msawczyn - really curious what you can find out! Please let me know if I can be any help with testing a new pre-release or so. Thanks a lot |
Thanks for the feedback, Michael! I've got that issue with MySQL, so it's definitely not specific to SqLite. Unfortunately also my project here is pretty complex, but I will try to see if I can reproduce it also with a minimal project - will try that directly - let you know shortly! |
I am able to reliably reproduce this also with a smaller project which I just sent to you via e-mail (michaelsawczyn[at]gmail[dot]com). Please let me know if you need any further information! Thanks |
Michael, I can't manage not to reproduce it 😀. Whenever I have 1 to many relation and use include I get related elements not filled with data. It happens the same on SqlServer and MySql. In my mysql project I could change relations to 0 to many and then it works, but in SqlServer project I can not do that since the project is mature. |
In your projects, have you enabled lazy loading or are you explicitly adding an |
Did you receive my example project via e-mail, Michael? No lazy loading enabled and as you can see in the very simple example queries there is also no |
The only files I got from you were for the collation settings. This issue is regarding 1..n associations. :-) |
Hm, I sent you a file via e-mail two days ago (on Saturday) with an example project - didn't you receive that? The e-mail subject was "EFCore Sample Project", perhaps it went into spam on your Google Mail account? |
Please see the following: This is a simple console app with two classes: Master and Detail, and a 1..N association between them. For portability, I've used LocalDB as the storage. Running the application will create the database and tables using the code-first migrations. Initially, no lazy loading is configured. You'll see that, with no .Include() calls, no Detail objects are returned. Uncommenting one of the lines in the Context partial will cause the association to be lazy loaded - the other can be left commented. Both are supplied just as alternatives and tests to ensure that the scenario works in either case. Running the app after uncommenting one of them shows that both queries (with or without .Include() calls) does indeed return the associated objects. @mciprijanovic and @ab-tools , could you please run these in your environment to make sure that there isn't anything special about my environment that's making this work and let me know the results? Thanks. |
Testing with SQL Server is not that quick for me as I don't even have that installed (thus also no LocalDB available), but changing your example to MySQL was simple, of course. But I can confirm that with your example in all cases (with or without lazy loading by enabling the first or second commented line) I always get 3 associated objects returned using MySQL. Really not sure what's the difference of the model I sent to you where I can reproduce the problem. Can you confirm, Michael, that you have received my e-mail from Saturday with the file "EFCoreTest.zip" attached? |
…ly included in any queries that use it (EFCore5 only). - Updated association tooltip to indicate which, if any, end is auto-included - Fix to calculate EF version number correctly when "Latest" was specified in designer (see #254)
Sorry. No files on Saturday. |
Strange, just forwarded you the e-mail again, this time without attachment, but an OneDrive link instead - did you receive it this time? |
Lazy loading disabled, using Include. |
Hi Michael. Your solution works because you use uniderectional relation. Use bidirectional and It will not work anymore. :) |
Good catch, @mciprijanovic, didn't notice that it was unidirectional! @msawczyn, do you also see the problem on your side when you try it with a bidirectional 1..N association? |
@msawczyn, sorry to bother, but did you had the chance to give that a try yourself in the meantime? |
I think I have the answer. I've pushed it out to /dist but it needs more testing, which will happen over the weekend. |
Thanks, @msawczyn, just gave it a quick try and this is actually looking pretty good to me on first sight! :-) I'll do some more tests tomorrow. |
@michael-sawczyn, reported bug still exists for .NET Core 3.x :( It is fixed for 5.x, already worked for 2.x but since we couldn't go to 5.x because of the Azure functions limitations, we had to choose EF core 3.0.10. When I tried the example already written it failed. :( So, still postponing migration to prod. |
There is an issue with the designer improperly mapping the selected EF version to capabilities. That's (hopefully) fixed in 3.0.4, whose RC1 is available at https://github.com/msawczyn/EFDesigner/blob/master/dist/Sawczyn.EFDesigner.EFModel.DslPackage.vsix If you could give that a try, I'd be in your debt. |
Just tried on vsix double click. Error: "The file is not valid vsix package." Log shows this: 2/12/2021 2:35:34 PM - Microsoft VSIX Installer |
Michael, this package works. I upgraded tool to 3.0.4.5, however, behaviour is the same. EF 2.2.6 and for example 5.0.3 work, but 3 or 3.1.10 not. Empty children list is what I get. |
@msawczyn, seems the bug is fixed in the new version you published: 3.0.4.7. I tried EF core 2.2.6, 3.1.2 and 5.0.3. Thanks, we can finnaly go to the new version of EF core in our project. Can you just confirm it? Thanks. |
One of the issues that release was targeted to fix was exactly this one. Glad to hear it's working for you. |
Hi. Here is the issue I found. Lets consider the simplest model with 2 classes: Parent and Child. Bidirectional relationship between them says that parent has a list of children and each child has one parent. I have the latest tool version 3.0.2.0 and EF core 5.0.1. Following statement does not return children:
var parents = dbContext.Parents.Include(x => x.Children);
Children collection is always empty although SQL profiler says that the query is good. If relation is changed to 0->n in the tool or EF core is set to 2.1, all works as expected.
The text was updated successfully, but these errors were encountered: