public void EFCore_Should_Support_Circular_References()
        {
            // Create new empty database
            using (var db = new SQLiteContext())
            {
                // Arrange
                var cr = new EntityFrameworkRepository <Category>(db, null, false);
                var c  = CreateCategory(100);
                cr.Create(c);
                cr.SaveChanges();

                // Detach all to avoid expansions already cached in the context
                cr.DetachAll();

                // Act
                var cdb = cr
                          .Include("Products.Parts.Product")
                          .Find().First();

                Assert.NotNull(cdb);
                var products = cdb.Products;

                // Assert
                Assert.NotNull(products);
                Assert.Equal(100, products.Count);
                var product = products.First();
                for (int i = 0; i < 10; i++)
                {
                    Assert.NotNull(product);
                    Assert.NotNull(product.Parts);
                    var part = product.Parts.First();
                    product = part.Product;
                }
            }
        }
        protected async Task IncludeTest(
            string includes,
            int productRows,
            int expectedProductRows,
            int expectedPartRows,
            Func <IEntityFrameworkRepository <Category>, int?, Task <Category> > getById)
        {
            // Create new empty database
            using (var db = new SQLiteContext())
            {
                // Arrange
                IEntityFrameworkRepository <Category> categoryRepository = new EntityFrameworkRepository <Category>(db)
                                                                           .Include(includes);
                var category = CreateCategory(productRows);
                categoryRepository.Create(category);
                // Detach all to avoid expansions already cached in the context
                categoryRepository.DetachAll();

                // Act
                category = await getById(categoryRepository, category.Id);

                // Assert
                Assert.NotNull(category);
                if (category.Products == null)
                {
                    Assert.Equal(0, expectedProductRows);
                }
                else
                {
                    Assert.Equal(expectedProductRows, category.Products.Count);
                    var product = category.Products.First();
                    if (product.Parts == null)
                    {
                        Assert.Equal(0, expectedPartRows);
                    }
                    else
                    {
                        Assert.Equal(expectedPartRows, product.Parts.Count);
                    }
                }
            }
        }
        public void EFCore_Should_Not_Support_Lazy_Load()
        {
            // Create new empty database
            using (var db = new SQLiteContext())
            {
                // Arrange
                var cr = new EntityFrameworkRepository <Category>(db, null, false);
                var c  = CreateCategory(100);
                cr.Create(c);
                cr.SaveChanges();

                // Detach all to avoid expansions already cached in the context
                cr.DetachAll();

                // Act
                var cdb = cr.Find().First();
                Assert.NotNull(cdb);

                // Assert
                // Looks like lazy loading is not supported in EF Core
                Assert.Null(cdb.Products);
            }
        }