private void RunEntity() { //var stopwatch = Stopwatch.StartNew(); var correlationId = Guid.NewGuid().ToString(); using (var context = new EntityContext()) { var parent = context.ParentEntities.FirstOrDefault(x => x.CorrelationId == correlationId); if (parent == null) { parent = new ParentEntity { CorrelationId = correlationId }; context.ParentEntities.Add(parent); context.SaveChanges(); } var entity = new Entity { ParentId = parent.Id, Name = Guid.NewGuid().ToString(), StatusCode = 0 }; context.Entities.Add(entity); context.SaveChanges(); for (int i = 0; i < 15; i++) { var statusCode = i; var entityId = entity.Id; AddEvent(entity.Id, statusCode, context); } //Console.WriteLine("* Entity id: {0}, took: {1}ms", entity.Id, stopwatch.ElapsedMilliseconds); } }
private void RunEntity() { //var stopwatch = Stopwatch.StartNew(); var correlationId = Guid.NewGuid().ToString(); var parentRepository = new ParentEntityRepository(); if (!parentRepository.Exists(correlationId)) { var parent = new ParentEntity { CorrelationId = correlationId }; parentRepository.Save(parent); } var entity = new Entity { CorrelationId = correlationId, Name = Guid.NewGuid().ToString(), StatusCode = 0 }; var entityRepository = new EntityRepository(); entityRepository.Save(entity); var collection = entityRepository.GetCollection(); for (int i = 0; i < 15; i++) { var statusCode = i; var entityId = entity.Id; AddEvent(entityId, statusCode, collection); } //Console.WriteLine("* Entity id: {0}, took: {1}ms", entity.Id, stopwatch.ElapsedMilliseconds); }
private void RunEntity() { //var stopwatch = Stopwatch.StartNew(); var correlationId = Guid.NewGuid().ToString(); var parentRepository = new ParentEntityRepository(); if (!parentRepository.Exists(correlationId)) { var parent = new ParentEntity { CorrelationId = correlationId }; parentRepository.Save(parent); } var entity = new Entity { CorrelationId = correlationId, Name = Guid.NewGuid().ToString(), StatusCode = 0 }; var entityRepository = new EntityRepository(); entityRepository.Save(entity); //var tasks = new List<Task>(); for (int i = 0; i < 15; i++) { var statusCode = i; var entityId = entity.Id; //tasks.Add(new Task(() => AddEvent(entityId, statusCode))); AddEvent(entityId, statusCode); } //tasks.ForEach(x => x.Start()); //Task.WaitAll(tasks.ToArray()); //Console.WriteLine("* Entity id: {0}, took: {1}ms", entity.Id, stopwatch.ElapsedMilliseconds); }
public void Save(ParentEntity parent, WriteConcern concern = null) { var collection = Db.GetCollection<ParentEntity>(); collection.Save(parent, concern ?? WriteConcern.Acknowledged); }