// This method copies the Customer objects with the orders attached to the Mongo db database private static void SetUpMongoDbData() { var mongoDb = GetMongoDatabase(); mongoDb.Drop(); mongoDb = GetMongoDatabase(); using (var efQueryRepository = new EntityFrameworkQueryRepository(new NRepository_NorthwindContext())) { // no proxy objects please var dbContext = (DbContext)efQueryRepository.ObjectContext; dbContext.Configuration.ProxyCreationEnabled = false; // load customers with orders attached var customers = efQueryRepository.GetEntities<Customer>( new EagerLoadingQueryStrategy<Customer>( p => p.Orders)).ToList(); // MongoDbRepository immediately calls the db when adding, modifying or deleting data. Use this implementation // to both set and get the concerns. (MongoDbUnitOfWorkRepository will only return the concerns after all the items have been saved ) using (IRepository mongoRepository = new MongoDbRepository(mongoDb)) { // Copy Ef data to mongo db customers.ForEach(customer => { //var result = mongoRepository.AddWithConcern(customer) mongoRepository.Add(customer); }); } } }
public void LoadTest() { var repository = new EntityFrameworkQueryRepository(new FamilyDbContext()); var person = repository.GetEntity <Parent>(p => p.Id == Names.IsabelleOsborne); person.Children.Count.ShouldEqual(0); repository.Load(person, p => p.Children); person.Children.Count.ShouldEqual(2); }
public void CheckPagingQueryStrategy() { var repository = new EntityFrameworkQueryRepository(new FamilyDbContext()); var c = repository.GetEntities<Animal>().ToList(); var children = repository.GetEntities<Child>( new OrderByQueryStrategy<Child>(p => p.LastName)); var pager = new FilterByPageQueryStrategy(2, 2, true); var results = children.AddQueryStrategy(pager); results.Count().ShouldEqual(2); pager.RowCount.ShouldEqual(5); }
public void CheckPagingQueryStrategy() { var repository = new EntityFrameworkQueryRepository(new FamilyDbContext()); var c = repository.GetEntities <Animal>().ToList(); var children = repository.GetEntities <Child>( new OrderByQueryStrategy <Child>(p => p.LastName)); var pager = new PagingQueryStrategy(2, 2, true); var results = children.AddQueryStrategy(pager); results.Count().ShouldEqual(2); pager.RowCount.ShouldEqual(5); }
public void CheckMaterialiseQueryStrategy() { Func<string> GetName = () => "Marc"; var repository = new EntityFrameworkQueryRepository(new FamilyDbContext()); // Show it's not working due to running in the db Assert.Throws<NotSupportedException>(() => { repository.GetEntity<Child>( new ExpressionQueryStrategy<Child>(p => p.FirstName == GetName())) .LastName.ShouldEqual("Burgess"); }); // Now show MaterialiseQueryStrategy does work repository.GetEntity<Child>( new MaterialiseQueryStrategy(), new ExpressionQueryStrategy<Child>(p => p.FirstName == GetName().ToString())) .LastName.ShouldEqual("Burgess"); }
public void CheckMaterialiseQueryStrategy() { Func <string> GetName = () => "Marc"; var repository = new EntityFrameworkQueryRepository(new FamilyDbContext()); // Show it's not working due to running in the db Assert.Throws <NotSupportedException>(() => { repository.GetEntity <Child>( new ExpressionQueryStrategy <Child>(p => p.FirstName == GetName())) .LastName.ShouldEqual("Burgess"); }); // Now show MaterialiseQueryStrategy does work repository.GetEntity <Child>( new MaterialiseQueryStrategy(), new ExpressionQueryStrategy <Child>(p => p.FirstName == GetName().ToString())) .LastName.ShouldEqual("Burgess"); }
public void ConditionalTests() { var _queryRepository = new EntityFrameworkQueryRepository(new FamilyDbContext()); var ss = new TextSearchSpecificationStrategy <Person>( "a", p => p.FirstName); var count_ = _queryRepository.GetEntities <Person>(ss).Count(); var rowCountCallback = default(Func <int>); var results = _queryRepository.GetEntities <Person>( ss, // new ConditionalQueryStrategy(true, // Removed as causes stack overflow when using PagingQueryStrat new OrderByQueryStrategy("FirstName"), new PagingQueryStrategy(0, 2, out rowCountCallback).OnCondition(true)); // var rowCount2 = rowCountCallback(); var rowCount = results.Count(); var XX = results.ToArray(); }
public void LoadTest() { var repository = new EntityFrameworkQueryRepository(new FamilyDbContext()); var person = repository.GetEntity<Parent>(p => p.Id == Names.IsabelleOsborne); person.Children.Count.ShouldEqual(0); repository.Load(person, p => p.Children); person.Children.Count.ShouldEqual(2); }
public void ConditionalTests() { var _queryRepository = new EntityFrameworkQueryRepository(new FamilyDbContext()); var ss = new MultipleTextSearchSpecificationStrategy<Person>( "a", p => p.FirstName); var count_ = _queryRepository.GetEntities<Person>(ss).Count(); var rowCountCallback = default(Func<int>); var results = _queryRepository.GetEntities<Person>( ss, new ConditionalQueryStrategy(true, new OrderByQueryStrategy("FirstName"), new PagingQueryStrategy(0, 2).OnCondition(true))); // var rowCount2 = rowCountCallback(); var rowCount = results.Count(); var XX = results.ToArray(); }