public Batch Create(Source source) { Batch batch; using (var dbContext = new TimberMillDbContext()) { batch = new Batch {Source = source}; dbContext.Batchs.Add(batch); dbContext.Entry(batch.Source).State = EntityState.Unchanged; dbContext.SaveChanges(); } return batch; }
public void Save(LogEvent logEvent) { using (var dbContext = new TimberMillDbContext()) { dbContext.Batchs.Attach(logEvent.Batch); dbContext.Sources.Attach(logEvent.Batch.Source); dbContext.LogEvents.Add(logEvent); //dbContext.Entry(logEvent.Batch).State = EntityState.Unchanged; //dbContext.Entry(logEvent.Batch.Source).State = EntityState.Unchanged; dbContext.SaveChanges(); } }
public Batch Create(Source source) { Batch batch; using (var dbContext = new TimberMillDbContext()) { batch = new Batch { Source = source }; dbContext.Batchs.Add(batch); dbContext.Entry(batch.Source).State = EntityState.Unchanged; dbContext.SaveChanges(); } return(batch); }
public Source GetOrCreate(string name, string category) { using (var dbContext = new TimberMillDbContext()) { var source = Get(dbContext, name, category); if (source == null) { source = new Source {Name = name, Category = category}; dbContext.Sources.Add(source); dbContext.SaveChanges(); } return source; } }
public Source GetOrCreate(string name, string category) { using (var dbContext = new TimberMillDbContext()) { var source = Get(dbContext, name, category); if (source == null) { source = new Source { Name = name, Category = category }; dbContext.Sources.Add(source); dbContext.SaveChanges(); } return(source); } }