C
C#8mo 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
Angius8mo ago
$code
MODiX
MODiX8mo 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
AaronOP8mo ago
one sec
Aaron
AaronOP8mo ago
No description
Aaron
AaronOP8mo ago
No description
Aaron
AaronOP8mo 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
Angius8mo ago
Not sure what that .heic file is
Aaron
AaronOP8mo ago
oh it was a image of the database
Aaron
AaronOP8mo ago
No description
Aaron
AaronOP8mo 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
Angius8mo ago
Well, it seems fine to me As in, it shoul;d be fetching all orders
Aaron
AaronOP8mo ago
yes including cusotmers if i remove the incldue cusomter it works its shwos everhting
Angius
Angius8mo ago
What happens when you ditch the includes and use a select instead?
Aaron
AaronOP8mo ago
do you have any idea why it is not so that would be select cusomter ill try
Angius
Angius8mo ago
No That would be selecting the data into a DTO class
Aaron
AaronOP8mo ago
oh ok what do you mean by this
Angius
Angius8mo 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
AaronOP8mo ago
i am trying that rn thanks
Aaron
AaronOP8mo ago
No description
Aaron
AaronOP8mo 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
Angius8mo ago
What is Customers? Is it a collection of customers?
Aaron
AaronOP8mo ago
a class yes
Angius
Angius8mo ago
Why does the error imply that it is, in fact, not?
Aaron
AaronOP8mo ago
ill show you my model
Aaron
AaronOP8mo ago
No description
Aaron
AaronOP8mo ago
thats in orders
Aaron
AaronOP8mo ago
No description
Angius
Angius8mo ago
That does not look like a collection to me
No description
Aaron
AaronOP8mo ago
oh my bad but one order can only have one cusotmer
Angius
Angius8mo ago
Why is it named plural, "Collections" then
Aaron
AaronOP8mo ago
idk i though thats just naming convetion
Angius
Angius8mo 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
AaronOP8mo ago
oh so on the front end I can not be like cusotmers.name etc
Angius
Angius8mo ago
You can just fetch the whole customer, sure
Aaron
AaronOP8mo ago
is there a way to get everthing
Angius
Angius8mo ago
But do you need to?
Aaron
AaronOP8mo 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
Angius8mo ago
You can just do Customer = o.Customers ig
Aaron
AaronOP8mo 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
Angius8mo ago
The way to do it without a DTO is the way you were doing it before Which is suitable for school projects
Aaron
AaronOP8mo ago
but that dosent work
Angius
Angius8mo 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
AaronOP8mo ago
ok thankk yoiu very much
Want results from more Discord servers?
Add your server