Mario K.
Mario K.
CC#
Created by Mario K. on 5/5/2024 in #help
.NET 6 web api - HttpClient.PostAsync not hitting HttpPost in controller
Hello ! I have a controller with [HttpPost] method, but httpclient.postasinc does not hit it. Instead it returns 400 (bad request).... DeleteAsync and GetAsync properly hit corresponding [HttpDelete] and [HttpGet] methods in the controller ... Any suggestions ?
25 replies
CC#
Created by Mario K. on 4/22/2024 in #help
✅ Help with LINK Async !
Hi ! I am having a trouble with this code: public async Task<IEnumerable<Customer>> GetAllAsync() { var customers = await dbSet.ToListAsync(); return customers; } Awaiting this correctly returns all customers. However, this code does not work : public async Task<IEnumerable<Customer>> GetAllAsync() { var c = await _unitOfWork.CustomerRepository.GetAllAsync();
return c; } and c is an EMPTY list - Data.Entities.Customer[0] !!!! What am I doing wrong ?? Thank you in advance !
85 replies
CC#
Created by Mario K. on 4/19/2024 in #help
How to perform nested one-to-many join in LINQ
I apologize if this is stupid, but how to return an IEnumerable<Receipt> that contains Product in this case: // Each Receipt can have many ReceiptDetals public class Receipt { public int Id { get; set; } public virtual ICollection<ReceiptDetail> ReceiptDetails { get; set; } = new List<ReceiptDetail>(); } // Each ReceiptDetail is related to one Product public class ReceiptDetail { public int Id { get; set; } // Other properties .... public int ProductId { get; set; }
public Product Product { get; set; } = new Product(); } // A Product can be present in none or many ReceiptDetails !!! public class Product { public int Id { get; set;}
// Other properties ... public virtual ICollection<ReceiptDetail> ReceiptDetails { get; set; } = new List<ReceiptDetail>(); } context.Receipt.Include(m => m.ReceiptDetail) returns a list of Receipt, with included ReceiptDetails, but Product within ReceiptDetails is NULL ! Also, context.Receipt.Include(m => m.ReceiptDetal).Include(x => x.Product) does not work, and neither does context.Receipt.Include(m => m.ReceiptDetal.Product) ... What am I missing ? Any suggestions or help is appreciated !
12 replies