protected void CreateDbContext() { _context = new ArvixeDB(); // Do NOT enable proxied entities, else serialization fails. //if false it will not get the associated certification and skills when we //get the applicants _context.Configuration.ProxyCreationEnabled = false; // Load navigation properties explicitly (avoid serialization trouble) _context.Configuration.LazyLoadingEnabled = false; // Because Web API will perform validation, we don't need/want EF to do so _context.Configuration.ValidateOnSaveEnabled = false; //DbContext.Configuration.AutoDetectChangesEnabled = false; // We won't use this performance tweak because we don't need // the extra performance and, when autodetect is false, // we'd have to be careful. We're not being that careful. }
public UnitOfWork(ArvixeDB dbContext) { _context = dbContext; }
public void TestMethod1() { // // TODO: Add test logic here // using (ArvixeDB context = new ArvixeDB()) { var newentities = context.Set <NewEntityPrime>(); var newentitiesalt = context.Set <NewEntityPrimeAlternate>(); var newsubs = context.Set <NewEntitySub>(); var newprime = newentities.FirstOrDefault(e => e.Name.ToLower() == "prime1"); if (newprime == null) { newprime = new NewEntityPrime() { Name = "Prime1" }; context.Set <NewEntityPrime>().Add(newprime); context.SaveChanges(); } var newalt = newentitiesalt.FirstOrDefault(e => e.Name.ToLower() == "alt1"); if (newalt == null) { newalt = new NewEntityPrimeAlternate() { Name = "Alt1" }; newentitiesalt.Add(newalt); context.SaveChanges(); } var newsub1 = newsubs.FirstOrDefault(s => s.RelatedInfo.ToLower() == "i'm related to prime1"); if (newsub1 == null) { newsub1 = new NewEntitySub() { ForeignKey_ID = newprime.ID, RelatedInfo = "I'm related to Prime1" }; newsubs.Add(newsub1); context.SaveChanges(); } var newsub2 = newsubs.FirstOrDefault(s => s.RelatedInfo.ToLower() == "i'm also related to prime1"); if (newsub2 == null) { newsub2 = new NewEntitySub() { ForeignKey_ID = newprime.ID, RelatedInfo = "I'm also related to Prime1" }; newsubs.Add(newsub2); context.SaveChanges(); } var newsub3 = newsubs.FirstOrDefault(s => s.RelatedInfo.ToLower() == "i'm related to alt1"); if (newsub3 == null) { newsub3 = new NewEntitySub() { ForeignKey_ID = newalt.ID, RelatedInfo = "I'm related to Alt1" }; newsubs.Add(newsub3); context.SaveChanges(); } } }