Bonjour,
J'utilise EF Core version 1.1 dans un projet Web API.
J'ai deux classes comme suit:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public partial class Category    {
        public Category()
        {
            Product = new HashSet<Product>();
        }
 
        public int CategoryId { get; set; }
        public string CategoryName { get; set; }
        public string Description { get; set; }
        public string CategoryImageUrl { get; set; }
        public virtual ICollection<Product> Product { get; set; }
    }
 
public partial class Product
    {
        public Product()
        {
            InvoiceLine = new HashSet<InvoiceLine>();
            OrderLine = new HashSet<OrderLine>();
 
        }
 
 
        public int ProductId { get; set; }
        public string ProductName { get; set; }
        public string ProductDescription { get; set; }
        public string BrandName { get; set; }
        public int? SupplierId { get; set; }
        public int? CategoryId { get; set; }
        public string BarCode { get; set; }
        public decimal? UnitPrice { get; set; }
        public short? UnitsInStock { get; set; }
        public string ImageUrl { get; set; }
        public string Status { get; set; }
        public int? LastEditedBy { get; set; }
        public DateTime? LastEditedWhen { get; set; }
 
        public virtual ICollection<InvoiceLine> InvoiceLine { get; set; }
        public virtual ICollection<OrderLine> OrderLine { get; set; }
        public virtual Category Category { get; set; }
        public virtual Suppliers Supplier { get; set; }
    }
Je fait du Eager Loading avec EF Core comme ceci dans mon repository:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
namespace NetCoreServiceLayer.Repository{
    public class CategoriesRepository : ICategoriesRepository
    {
 
        private PointOfSaleDBContext _context;
 
        public CategoriesRepository(PointOfSaleDBContext context)
        {
            _context = context;
        } 
 
        public async Task<IEnumerable<Category>> GetAsync()
        {
 
            return await _context.Category
                         .Include(pdt => pdt.Product)
                         .ToListAsync();
        }
   }
 
 }
Mais EF Core me retourne seulement un enregistrement alors qu'il y a des centaines de lignes dans ma table Category. Ai-je raté quelque chose? Merci d'avance pour vos apports.