static void SimpleThingy() { SimpleRepoThingy repo = new SimpleRepoThingy(); //set the juicy context... var efContext = new TheoreticalEntities(); efContext.Configuration.LazyLoadingEnabled = false; efContext.Configuration.ProxyCreationEnabled = false; //efContext.Configuration.ValidateOnSaveEnabled = false; var context = new DataMapper.Repositories.EntityFrameworkRepositoryContext<TheoreticalEntities>(efContext); repo.Context = context; var findResult = repo.TryFind(134); var addOrder = CreateNewOrderEntity(); //addOrder.RenamedStatus = StatusEnum.Giggidy; //sl.Add(addOrder); repo.Add(addOrder); context.SaveChanges(); var addFindResult = repo.TryFind(addOrder.OrderId); //remove last and add a new one. addFindResult.OrderItem.Remove(addFindResult.OrderItem.Last()); addFindResult.OrderItem.Add(new OrderItemEntity() { HasSerialNumber = false, SalePrice = 1000M, SerialNumber = "ADDEDITEM", Upc = "ADDUPC", ConcurrencyId = 0 }); repo.Update(addFindResult); context.SaveChanges(); addFindResult.OrderInformation.Last().TrackingNumber = "Giggidy"; repo.Update(addFindResult); context.SaveChanges(); repo.Delete(addFindResult); context.SaveChanges(); }
static void PerformanceUpdateRawTest(Int32 numberOfInserts, Boolean proxiesEnabled, Boolean lazyEnabled) { DateTime started = DateTime.Now; Int32 loopymax = numberOfInserts; TheoreticalEntities context = new TheoreticalEntities(); context.Configuration.ProxyCreationEnabled = proxiesEnabled; context.Configuration.LazyLoadingEnabled = lazyEnabled; var updateTarget = context.OrderEntity .Include(a => a.OrderItem) .Include(a => a.OrderInformation) .First(); for (Int32 i = 0; i < loopymax; i++) { updateTarget.OptionalNote = "Giggidy" + i.ToString(); if (i % 2 == 0) { var infoitem = context.OrderInformationEntity.CreateAndAdd(); infoitem.TrackAmount = Convert.ToDecimal(i) * 100; infoitem.TrackDate = DateTime.Now; infoitem.TrackingNumber = "tracky" + i.ToString(); updateTarget.OrderInformation.Add(infoitem); } else { var minDate = updateTarget.OrderInformation .Where(a=>a.OrderInformationId >0).Min(a => a.OrderInformationId); context.OrderInformationEntity.Remove(updateTarget.OrderInformation .Where(a => a.OrderInformationId == minDate).First()); //updateTarget.OrderInformation.Remove(); } context.SaveChanges(); } Console.WriteLine("Performance update raw time to complete:" + DateTime.Now.Subtract(started).TotalSeconds.ToString()); }
static void PerformanceUpdate() { var context = new TheoreticalEntities(); context.OrderEntity.RemoveAll(context.OrderEntity.ToArray()); context.SaveChanges(); PerformanceAddMapperTest(1, false, false); PerformanceUpdateMapperTest(500, true, false); context = new TheoreticalEntities(); context.OrderEntity.RemoveAll(context.OrderEntity.ToArray()); context.SaveChanges(); PerformanceAddMapperTest(1, false, false); PerformanceUpdateRawTest(500, true, false); }
static void PerformanceAddRawTest(Int32 numberOfInserts, Boolean proxiesEnabled, Boolean lazyEnabled) { DateTime started = DateTime.Now; Int32 loopymax = numberOfInserts; TheoreticalEntities context = new TheoreticalEntities(); context.Configuration.ProxyCreationEnabled = proxiesEnabled; context.Configuration.LazyLoadingEnabled = lazyEnabled; for (Int32 i = 0; i < loopymax; i++) { var orderEntity = context.OrderEntity.CreateAndAdd(); orderEntity.Number = "4000" + Guid.NewGuid().ToString(); orderEntity.OrderDate = DateTime.Now; orderEntity.Status = (Int32)StatusEnum.Giggidy; orderEntity.TaxRate = (34.23m); orderEntity.ConcurrencyId = 0; orderEntity.OptionalNote = null; orderEntity.OptionalPrice = 123M; orderEntity.OrderItem = new List<OrderItemEntity>() { new OrderItemEntity() { ConcurrencyId = 0, HasSerialNumber = false, SalePrice = 34.12M, SerialNumber = "", Upc = "MYUPC" }, new OrderItemEntity() { ConcurrencyId = 0, HasSerialNumber = true, SalePrice = 134.12M, SerialNumber = "ASerialnumber", Upc = "OHTERUPC" } }; orderEntity.OrderInformation = new List<OrderInformationEntity>() { new OrderInformationEntity() { TrackAmount = 100, TrackDate = DateTime.Now, TrackingNumber = "TRK100500" }, new OrderInformationEntity() { TrackAmount = null, TrackDate = null, TrackingNumber = null } }; context.SaveChanges(); } Console.WriteLine("Performance add raw time to complete:" + DateTime.Now.Subtract(started).TotalSeconds.ToString()); }
static void Main(string[] args) { try { TheoreticalEntities context = new TheoreticalEntities(); context.OrderEntity.RemoveAll(context.OrderEntity.ToArray()); context.SaveChanges(); //this uses straight up mapping DataMapBlock(); //the thingie //SimpleThingy(); //this shows how you can rename things //DataMapBlockOdd(); //TypeMapper(); //TestTwo(); } catch (Exception ex) { //expect this... Console.WriteLine(ex.ToString()); } Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
static void DataMapBlock() { try { OrderDataMapBlock dataMapBlock = new OrderDataMapBlock(); //set the juicy context... var efContext = new TheoreticalEntities(); efContext.Configuration.LazyLoadingEnabled = false; efContext.Configuration.ProxyCreationEnabled = false; //efContext.Configuration.ValidateOnSaveEnabled = false; var context = new DataMapper.Repositories.EntityFrameworkRepositoryContext<TheoreticalEntities>(efContext); dataMapBlock.Context = context; var findResult = dataMapBlock.TryFind(134); var addOrder = CreateNewOrder(); //sl.Add(addOrder); dataMapBlock.Add(addOrder); context.SaveChanges(); var addFindResult = dataMapBlock.TryFind(addOrder.OrderId); //remove last and add a new one. addFindResult.OrderItem.Remove(addFindResult.OrderItem.Last()); addFindResult.OrderItem.Add(new OrderItem() { HasSerialNumber = false, SalePrice = 1000M, SerialNumber = "ADDEDITEM", Upc = "ADDUPC", ConcurrencyId = 0 }); addFindResult.MultiKey.Remove(addFindResult.MultiKey.First()); addFindResult.MultiKey.Add(new MultiKey() { KeyOne = 100, KeyTwo = Guid.NewGuid(), KeyThree = "GiggidyUp", Name= "Multi", Number= "23333", ConcurrencyId = 99 }); dataMapBlock.Update(addFindResult); context.SaveChanges(); addFindResult.OrderInformation.Last().TrackingNumber = "Giggidy"; dataMapBlock.Update(addFindResult); context.SaveChanges(); dataMapBlock.Delete(addFindResult); context.SaveChanges(); Order whatever; Order whatever2; using (var tranny = new System.Transactions.TransactionScope()) { whatever = CreateNewOrder(); whatever.Number = "F**k"; dataMapBlock.Add(whatever); context.SaveChanges(); whatever2 = CreateNewOrder(); whatever2.Number = "YeahMan"; dataMapBlock.Add(whatever2); context.SaveChanges(); tranny.Complete(); } whatever = whatever; } catch (Exception ex) { Console.Write(ex.ToString()); } Console.WriteLine("Press any key to exit"); Console.ReadKey(); }