public void EfCore_FindAll_With_Include_And_Predicate_In_Specs_LazyLoads_Email() { var repository = new EfCoreRepository <Contact, string>(dbContext); var findAllBySpec = new Specification <Contact>(obj => obj.ContactId == "1") .And(obj => obj.EmailAddresses.Any(m => m.Email == "*****@*****.**")); var specification = new Specification <Contact>(obj => obj.Name == "Test User 1"); findAllBySpec.FetchStrategy = new GenericFetchStrategy <Contact>(); findAllBySpec.FetchStrategy .Include(obj => obj.EmailAddresses); // NOTE: This line will erase my FetchStrategy from above if (null != specification) { findAllBySpec = findAllBySpec.And(specification); } var contact = repository.FindAll(findAllBySpec).First(); contact.Name.ShouldBe("Test User 1"); dbContext.QueryLog.Count(filterSelects).ShouldBe(2); contact.EmailAddresses.First().Email.ShouldBe("*****@*****.**"); dbContext.QueryLog.Count(filterSelects).ShouldBe(2); repository.FindAll(findAllBySpec).Count().ShouldBe(1); }
public void CompoundKeyRepository_Should_Work() { var dbPath = EfDataDirectoryFactory.Build(); ICompoundKeyRepository <User, string, int> repository = new EfCoreRepository <User, string, int>(context); repository.Add(new User { Username = "******", Age = 21, FullName = "Jeff - 21" }); repository.Add(new User { Username = "******", Age = 31, FullName = "Jeff - 31" }); repository.Add(new User { Username = "******", Age = 41, FullName = "Jeff - 41" }); repository.Add(new User { Username = "******", Age = 31, FullName = "Ben - 31" }); repository.Add(new User { Username = "******", Age = 41, FullName = "Ben - 41" }); repository.Add(new User { Username = "******", Age = 51, FullName = "Ben - 51" }); repository.Get("jeff", 31).FullName.ShouldBe("Jeff - 31"); repository.Get("ben", 31).FullName.ShouldBe("Ben - 31"); repository.Get("jeff", 41).FullName.ShouldBe("Jeff - 41"); repository.FindAll(x => x.Age == 31).Count().ShouldBe(2); }
public void Delete_Loop_With_Cache_And_Ef() { var cachingStrategy = new StandardCachingStrategy <Contact, string>(cacheProvider); var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <TestObjectContextCore>() .UseSqlite(connection) .Options; var context = new TestObjectContextCore(options); context.Database.EnsureCreated(); var repository = new EfCoreRepository <Contact, string>(context, cachingStrategy); repository.Add(new Contact() { ContactId = "1", Name = "Contact1", ContactTypeId = 1 }); repository.Add(new Contact() { ContactId = "2", Name = "Contact2", ContactTypeId = 2 }); repository.Add(new Contact() { ContactId = "3", Name = "Contact3", ContactTypeId = 2 }); repository.FindAll(x => x.ContactTypeId == 2); repository = new EfCoreRepository <Contact, string>(new TestObjectContextCore(options), cachingStrategy); repository.Delete(x => x.ContactTypeId == 2); }