Why isn't the blogposts tags being pulled?
So the first screenshot is of the index page, where I'm trying to display the tags.
The second, third and fourth screenshots are of the Blogpost, Tag, and BlogpostTag models
The next 3 images are of each of the databases, in the same order.
finally, here is a screenshot of the webapp running. Why isn't it finding the tags when they exist in the DB?








30 Replies
you didn't include the code that runs the query
I assume you have an EF Core query
you need to either project into a dto, or do an Include
for the tags navigation
and remove the check for null, do an assert instead
gib query
sure, 2 secs

BlogpostsController
Huh, seems fine
Does the debugger also show that
blogpost
here doesn't contain tags?
As a side note, you can just set the relationship between tags and blogposts directly, EF will figure out the pivot table@Angius How would I set it directly, just like the new line I added?

ye
Just
List<Tag> Tags
on the blogpost, and List<Blogpost> Blogposts
on the tagAhh, the guide I was using said to make a connector class?
Wouldn't make them nullable either
That's basically an interface right, what my old code did?
Well, the guide probably wasn't the freshest
Your code does not contain any interfaces whatsoever
Besides
IActionResult
I guessahh, so the connector class is pointless?
It has its uses
But you can always configure the relationship to use it
While keeping the navigation between tags and posts direct

Example from my project, configuration of
Story
ohhhh
Just set it to
[]
public List<Tag> Tags { get; set; } = [];

so do I just change this to now just:
.Include(t => t.Tag)
.FirstOrDefaultAsync(x => x.Id == id);
as the Include doesn't need to include the blogpostTags
@Angius it broke my context
Yes, that's how you do it, just include the tags

Broke the context how?
Don't configure the
BlogpostTags

Every change I make is wrong xD Any chance you have 2 mins for a voice call to run through it quick and I'll share my screen??
Not right now, sorry
Okay, no worries
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
I should have just posted the repo link xD
Just need to check my gitignore worked properly
will post it shortly
Worked this out. I hadn't passed the BlogpostTags into the Index method in the controller before returning the View