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 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 List<LogEvent> GetAll(Source source) { var events = new List<LogEvent>(); using (var dbContext = new TimberMillDbContext()) { events = dbContext .LogEvents .Include("Batch") .Include("Batch.Source") .Where(e => e.Batch.Source.Id == source.Id).ToList(); } return events; }
public List <LogEvent> GetAll(Source source) { var events = new List <LogEvent>(); using (var dbContext = new TimberMillDbContext()) { events = dbContext .LogEvents .Include("Batch") .Include("Batch.Source") .Where(e => e.Batch.Source.Id == source.Id).ToList(); } return(events); }
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); } }
private Source Get(TimberMillDbContext dbContext, string name, string category) { return(dbContext.Sources.Where(s => s.Name == name && s.Category == category).FirstOrDefault()); }
private Source Get(TimberMillDbContext dbContext, string name, string category) { return dbContext.Sources.Where(s => s.Name == name && s.Category == category).FirstOrDefault(); }