Hi @Asjad Butt ,
System.InvalidOperationException: The expression 'p.BranchName' is invalid inside an 'Include' operation, since it does not represent a property access: 't => t.MyProperty'. To target navigations declared on derived types, use casting ('t => ((Derived)t).MyProperty') or the 'as' operator ('t => (t as Derived).MyProperty'). Collection navigation access can be filtered by composing Where, OrderBy(Descending), ThenBy(Descending), Skip or Take operations.
When using the Include or ThenInclude , we need to specify a navigation property, but in your query statement, the BranchName is just a string type, instead of the navigation property. So, it will show the above error.
To solve it, try to modify your code as below: I assume you want to load the BranchAdmin
entity, change the BranchName
to BranchAdmin
:
var students = await context.Students
.Include(p => p.Branch)
.ThenInclude(b => b.BranchAdmin)
.Include(p => p.Guardian)
.ToListAsync();
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion