public U?GetId(string name) { if (name == null) { return(null); } if (!NameMap.ContainsKey(name)) { using (Models.BodyDbContext ctx = new Models.BodyDbContext()) { T map = ctx.Set <T>().FirstOrDefault(v => v.Name == name); if (map == null) { map = new T { Name = name }; ctx.Set <T>().Add(map); ctx.SaveChanges(); } IdMap[map.Id] = map; NameMap[map.Name] = map; } } return(NameMap[name].Id); }
public XDatabase SetContext(Models.BodyDbContext ctx) { _Context = ctx; _SystemInserter = new Models.DbSystemInserter(ctx); _BodyInserter = new Models.DbBodyInserter(ctx); _ScanInserter = new Models.DbScanInserter(ctx); _ScanHeaderInserter = new Models.DbScanHeaderInserter(ctx); _ScanUpdater = new Models.DbScanUpdater(ctx); return(this); }
public NameIdMap(IEnumerable <T> seed) { using (Models.BodyDbContext ctx = new Models.BodyDbContext()) { T[] maps = ctx.Set <T>().ToArray(); if (maps.Length == 0) { maps = seed.ToArray(); ctx.Set <T>().AddRange(maps); ctx.SaveChanges(); } foreach (T map in maps) { NameMap[map.Name] = map; IdMap[map.Id] = map; } } }