Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EF 7 not loading my entities when using Eager or Explicit loading... #31009

Closed
vsfeedback opened this issue May 31, 2023 · 1 comment
Closed

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


[severity:It bothers me. A fix would be nice]
Hello and thank you for reading... I think I found a bug and I would really appreciate any help if I'm missing something, it would be nice if you point out what the problem is.

I do have a class called FACT_Entry, which has a property List<FactComment> comments, each of these comments has a User (AppIdentityUser : IdentityUser), and they are linked through a key of type string. to simplify my classes are something like this: (reduced for simplicity)

public class FACT_Entry
{
public Guid tool_guid { get; set; }
public virtual List comments { get; set; } = new();
public string tool_name { get; set; }
}
public class FactComment
{
public Guid comment_guid { get; set; }
public Guid tool_guid { get; set; }
public string Comment { get; set; }
public string? created_by { get; set; }
public virtual AppIdentityUser User { get; set; }
}
public class AppIdentityUser : IdentityUser
{
public virtual List FactComments { get; set; }
}

In other words... each FACT tool has a list of comments, and each comment has the ID of the Identity user that created it, represented by AppIdentityUser class that inherits IdentityUser. I'm trying to load a single tool, with its comments and the user who created it, so I created something like this:

        using TSMC_ODS_DbContext db = await odsContextFactory.CreateDbContextAsync(); //create my db context from factory

        Editable_FACT = await db.FACT
                            .Include(FACT => FACT.comments)
                            .ThenInclude(comment => comment.User)                                
                            .FirstOrDefaultAsync(f => f.tool_name == "KEMGH5"); //KEMGH5 just a random name

THE PROBLEM is that I get the list of comments, but nothing from the ThenInclude, (no User, is null...) I did check if the SQL generated from EF and it returned the list as follows:
screenshot1.png

I did check my relationships and all are fine, indeed if not, EF could not find the info I want but it does, as we saw on the image.

I tried to use explicit loading but the result is the same, is this a bug? am I missing something? any help on this will be appreciated, I spent hours already not sure what to do here...

As usual, I cannot send you my whole project and database, as this belongs to my boss, but I can offer you remote access if you want to come and play by to find what's going on... thank you.


Original Comments

Feedback Bot on 5/22/2023, 04:31 AM:

(private comment, text removed)


Original Solutions

(no solutions)

@ajcvickers ajcvickers transferred this issue from dotnet/ef6 May 31, 2023
@ajcvickers
Copy link
Contributor

Duplicate of #30943

@ajcvickers ajcvickers marked this as a duplicate of #30943 May 31, 2023
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants