C
C#9mo ago
Aaron

anybody know why in Asp.net mvc the data is in the database but not showing up on the index

I have a order and cusotmers model. When i add a .includ customer in the order query. it jsut show tow reuslts. EVen thou there is mroe in the databse. All the relastionships are set up correctly as it is adding to data base
43 Replies
Angius
Angius9mo ago
$code
MODiX
MODiX9mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Aaron
AaronOP9mo ago
one sec
Aaron
AaronOP9mo ago
No description
Aaron
AaronOP9mo ago
No description
Aaron
AaronOP9mo ago
hey @ZZZZZZZZZZZZZZZZZZZZZZZZZ, The probelm I have is adding the include stament include cusotmers only shows these two reuslts. Even though if you look at the pciture of the database there is alot more. Do you have any idea why this happing i have spent like 10 hours trying to fix this.
Angius
Angius9mo ago
Not sure what that .heic file is
Aaron
AaronOP9mo ago
oh it was a image of the database
Aaron
AaronOP9mo ago
No description
Aaron
AaronOP9mo ago
why is the include customers braking it if i dont put that i will display everthing. The cusomter mdoel inheirtes form the built in apilalction user class but all the relastioships are set up right as it is adding to the data base @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius9mo ago
Well, it seems fine to me As in, it shoul;d be fetching all orders
Aaron
AaronOP9mo ago
yes including cusotmers if i remove the incldue cusomter it works its shwos everhting
Angius
Angius9mo ago
What happens when you ditch the includes and use a select instead?
Aaron
AaronOP9mo ago
do you have any idea why it is not so that would be select cusomter ill try
Angius
Angius9mo ago
No That would be selecting the data into a DTO class
Aaron
AaronOP9mo ago
oh ok what do you mean by this
Angius
Angius9mo ago
I mean exactly and precisely what I said
var orders = await _context.Orders
.Select(o => new OrderDto {
Id = o.Id,
// ...
Status = o.Status.Name,
Customers = o.Customers.Select(c => c.Name).ToList()
})
.ToListAsync();
var orders = await _context.Orders
.Select(o => new OrderDto {
Id = o.Id,
// ...
Status = o.Status.Name,
Customers = o.Customers.Select(c => c.Name).ToList()
})
.ToListAsync();
for example
Aaron
AaronOP9mo ago
i am trying that rn thanks
Aaron
AaronOP9mo ago
No description
Aaron
AaronOP9mo ago
i feel this could be the same reason the .include did not work as well could this be beacuse cusomter is iherting form the identiy user pre built in class @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius9mo ago
What is Customers? Is it a collection of customers?
Aaron
AaronOP9mo ago
a class yes
Angius
Angius9mo ago
Why does the error imply that it is, in fact, not?
Aaron
AaronOP9mo ago
ill show you my model
Aaron
AaronOP9mo ago
No description
Aaron
AaronOP9mo ago
thats in orders
Aaron
AaronOP9mo ago
No description
Angius
Angius9mo ago
That does not look like a collection to me
No description
Aaron
AaronOP9mo ago
oh my bad but one order can only have one cusotmer
Angius
Angius9mo ago
Why is it named plural, "Collections" then
Aaron
AaronOP9mo ago
idk i though thats just naming convetion
Angius
Angius9mo ago
That's the worst naming convention I've seen in my entire life and fuck whoever decided to impose it on this project Regardless Since it's not a collection, we cannot use LINQ So... you just get what you need from the customer directly
var orders = await _context.Orders
.Select(o => new OrderDto {
Id = o.Id,
// ...
Status = o.Status.Name,
CustomerName = o.Customers.Name
})
.ToListAsync();
var orders = await _context.Orders
.Select(o => new OrderDto {
Id = o.Id,
// ...
Status = o.Status.Name,
CustomerName = o.Customers.Name
})
.ToListAsync();
for example
Aaron
AaronOP9mo ago
oh so on the front end I can not be like cusotmers.name etc
Angius
Angius9mo ago
You can just fetch the whole customer, sure
Aaron
AaronOP9mo ago
is there a way to get everthing
Angius
Angius9mo ago
But do you need to?
Aaron
AaronOP9mo ago
ya ig becuase the admin should be able to see the cusotmers detials do i have to type each feild or is there a way to select the whole thing
Angius
Angius9mo ago
You can just do Customer = o.Customers ig
Aaron
AaronOP9mo ago
ok ill try thank you one last thing is there a way to do it wihto a dto or is it needed since it is not a collection
Angius
Angius9mo ago
The way to do it without a DTO is the way you were doing it before Which is suitable for school projects
Aaron
AaronOP9mo ago
but that dosent work
Angius
Angius9mo ago
But only to a point, then I'd start docking points It should work Which is why I told you to try the proper way, using a DTO If that still doesn't work, something else is broken
Aaron
AaronOP9mo ago
ok thankk yoiu very much
Want results from more Discord servers?
Add your server