fromliberty
fromliberty
CC#
Created by fromliberty on 12/1/2023 in #help
getting null error
its same code in #web i realized i wasnt doing include
5 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
confusing part is querying many-to-many relationships in linq
160 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
then i cant fetch label
160 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
if i delete that, all problems gone
160 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
No description
160 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
figured out, but still cant load label 🤔
"labelProducts": [
{
"labelProductId": 0,
"productId": 0,
"labelId": 1,
"product": null,
"label": null
}
],
"labelProducts": [
{
"labelProductId": 0,
"productId": 0,
"labelId": 1,
"product": null,
"label": null
}
],
`
160 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
No description
160 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
maybe its automapper error ?
160 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
similar error
160 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
No description
160 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
weirdly
160 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
it has 4 errors lol
160 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
code itself:
public async Task<IEnumerable<ProductDto>> GetProducts()
{
var product = await _db.Products
.Select(p => new ProductDto {
Name = p.Name,
Description = p.Description,
Colours = p.Colours.Select(c => new ColourDto {
Id = c.Id,
Name = c.Name, // we only load what we need to show the colour
Img = c.Img,
Quantity = c.Quantity
}).ToList(),
LabelProducts = p.LabelProducts.Select(l => new LabelProductDto {
LabelId = l.LabelId,
Label = l.Label // and only what we need for the label
}).ToList(),
Price = p.Price,
})
.ToListAsync(); // we only load the requested product
return _mapper.Map<List<ProductDto>>(productList);
}
public async Task<IEnumerable<ProductDto>> GetProducts()
{
var product = await _db.Products
.Select(p => new ProductDto {
Name = p.Name,
Description = p.Description,
Colours = p.Colours.Select(c => new ColourDto {
Id = c.Id,
Name = c.Name, // we only load what we need to show the colour
Img = c.Img,
Quantity = c.Quantity
}).ToList(),
LabelProducts = p.LabelProducts.Select(l => new LabelProductDto {
LabelId = l.LabelId,
Label = l.Label // and only what we need for the label
}).ToList(),
Price = p.Price,
})
.ToListAsync(); // we only load the requested product
return _mapper.Map<List<ProductDto>>(productList);
}
`
160 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
to show errors, ss'ed instead
160 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
No description
160 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
yeah
160 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
public DbSet<Product> Products { get; set; }
160 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
_context.Products.Select one
160 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
not those
160 replies
CC#
Created by fromliberty on 11/30/2023 in #help
my response
main select gives erorr
160 replies