public void Init(System.Data.Entity.DbContext db) { List <Tuple <string, string> > l = new List <Tuple <string, string> >(); l.Add(Tuple.Create("管理主页", "supervise/main/index")); l.Add(Tuple.Create("审核", "supervise/audit/index")); l.Add(Tuple.Create("用户", "supervise/appusers/index")); l.Add(Tuple.Create("货币", "supervise/coin/index")); l.Add(Tuple.Create("合约", "supervise/contracts/index")); l.Add(Tuple.Create("论坛", "supervise/forum/index")); l.Add(Tuple.Create("帮助", "supervise/helper/index")); l.Add(Tuple.Create("新闻", "supervise/new/index")); l.Add(Tuple.Create("数据", "supervise/tradedata/index")); l.Add(Tuple.Create("安全", "supervise/security/index")); l.Add(Tuple.Create("监控", "supervise/snap/index")); l.Add(Tuple.Create("参数", "supervise/parameter/index")); l.Add(Tuple.Create("网站参数", "supervise/siteParameter/index")); l.Add(Tuple.Create("交易用户", "supervise/appusers/index")); List <Menu> lm = new List <Menu>(); for (int i = 0; i < l.Count; i++) { var m = new Menu { Id = i + 1, Name = l[i].Item1, Url = l[i].Item2 }; lm.Add(m); } db.Set <Menu>().AddOrUpdate(lm.ToArray()); db.SaveChanges(); }
/// <summary> /// 导出 /// </summary> //public void Export(string directory) //{ //} /// <summary> /// 导入基础数据 /// </summary> /// <param name="context">数据库实例</param> /// <param name="directory"></param> /// <param name="orderFile"></param> /// <param name="importConfig">部分导入基础数据时可选</param> public void Import(System.Data.Entity.DbContext context, IEnumerable <SeedImportConfig> importConfig = null) { try { Type t = typeof(HSJXEntities); PropertyInfo[] properties = t.GetProperties(); IEnumerable <PropertyInfo> pInfos = this.GetOrderedProperties(properties, this.DataDirectory, this.DataOrderFile); foreach (PropertyInfo pInfo in pInfos) { try { if (judgeTableImport(pInfo.Name, importConfig) == false) { continue; } object dbSet = pInfo.GetValue(context); MethodInfo dbSetAddMethod = dbSet.GetType().GetMethod("Add"); if (pInfo.PropertyType.GenericTypeArguments.Length > 0) { object deserializeResult = this.Deserialize(this.DataDirectory, pInfo.PropertyType.GenericTypeArguments[0]); //Log.Info(string.Format("开始导入表{0}数据", pInfo.PropertyType.GenericTypeArguments[0].Name)); IEnumerable list = deserializeResult as IEnumerable; if (list != null) { foreach (object o in list) { if (judgeRecordImport(pInfo.Name, o, importConfig) == false) { continue; } dbSetAddMethod.Invoke(dbSet, new object[] { o }); } } // Log.Info(string.Format("导入表{0}数据结束", pInfo.PropertyType.GenericTypeArguments[0].Name)); } context.SaveChanges(); } catch (Exception e) { // Log.Info(string.Format("导入表{0}数据结束", pInfo.PropertyType.GenericTypeArguments[0].Name), e); } } // Log.Info("导入数据库数据成功"); } catch (Exception e) { // Log.Info("导入数据库数据失败", e); } }
public override void Save(System.Data.Entity.DbContext db, DbSet <DbOption> dbOptions, bool saveInstantly = false) { dbOptions.AddOrUpdate(new DbOption(Key, Num.Value.ToString())); if (saveInstantly) { db.SaveChanges(); } }
public override void Save(System.Data.Entity.DbContext db, DbSet <DbOption> dbOptions, bool saveInstantly = false) { dbOptions.AddOrUpdate(new DbOption(Key, TabOrder.JoinAsString(","))); if (saveInstantly) { db.SaveChanges(); } }
public override void Save(System.Data.Entity.DbContext db, DbSet <DbOption> dbOptions, bool saveInstantly = false) { dbOptions.AddOrUpdate(new DbOption(Key, string.Join(",", Gv.SelectedItems.IColToArray().Select(i => i.GetType().GetProperty(ByProperty)?.GetValue(i, null)).OrderBy(id => id)))); if (saveInstantly) { db.SaveChanges(); } }
public override void Save(System.Data.Entity.DbContext db, DbSet <DbOption> dbOptions, bool saveInstantly = false) { dbOptions.AddOrUpdate(new DbOption(Key, Dp.SelectedDate != null ? Dp.SelectedDate.ToString() : null)); if (saveInstantly) { db.SaveChanges(); } }
public override void Save(System.Data.Entity.DbContext db, DbSet <DbOption> dbOptions, bool saveInstantly = false) { dbOptions.AddOrUpdate(new DbOption(Key, (Cb.IsChecked == true).ToInt().ToString())); if (saveInstantly) { db.SaveChanges(); } }
public override void Save(System.Data.Entity.DbContext db, DbSet <DbOption> dbOptions, bool saveInstantly = false) { dbOptions.AddOrUpdate(new DbOption(Key, string.Join(",", Mddl.SelectedItems.Cast <DdlItem>().Select(item => item.Index)))); if (saveInstantly) { db.SaveChanges(); } }
public override void Save(System.Data.Entity.DbContext db, DbSet <DbOption> dbOptions, bool saveInstantly = false) { dbOptions.AddOrUpdate(new DbOption(Key, ((DdlItem)Ddl.SelectedItem).Index.ToString())); if (saveInstantly) { db.SaveChanges(); } }
public override void Save(System.Data.Entity.DbContext db, DbSet <DbOption> dbOptions, bool saveInstantly = false) { var isExtended = TilesMenu.IsFullSize; dbOptions.AddOrUpdate(new DbOption(Key, isExtended.ToString())); if (saveInstantly) { db.SaveChanges(); } }
public void Save(System.Data.Entity.DbContext db, DbSet <DbOption> dbOptions, bool saveEachControlInstantly = false) { foreach (var cs in ControlStates) { cs.Save(db, dbOptions, saveEachControlInstantly); } if (!saveEachControlInstantly) { db.SaveChanges(); } }
public void SaveFiles(List <FileInfoEntity> files) { var fileSet = _context.Set <FileInfoEntity>(); fileSet.AddRange(files); _context.SaveChanges(); //var db = new RepositoryFactory().BaseRepository().BeginTrans(); //try //{ // db.Insert(files); // db.Commit(); //} //catch (Exception e) //{ // db.Rollback(); // throw e; //} }
public override void Save(System.Data.Entity.DbContext db, DbSet <DbOption> dbOptions, bool saveInstantly = false) { dbOptions.AddOrUpdate(new DbOption(Key, Rbs.Select((rb, i) => new { i, rb }).Single(el => el.rb.IsChecked == true).i.ToString())); if (saveInstantly) { db.SaveChanges(); } }
/// <summary> /// 将在此上下文中所做的所有更改保存到基础数据库。<paramref name="validateOnSaveEnabled"/> 参数指示在调用 SaveChanges() 时,是否应自动验证所跟踪的实体。 /// </summary> /// <param name="context">表示当前数据库访问上下文 <see cref="System.Data.Entity.DbContext"/> 对象。</param> /// <param name="validateOnSaveEnabled">指示在调用 SaveChanges() 时,是否应自动验证所跟踪的实体。</param> /// <returns>已写入基础数据库的对象的数目。</returns> public static int SaveChanges(this System.Data.Entity.DbContext context, bool validateOnSaveEnabled) { bool enabled = context.Configuration.ValidateOnSaveEnabled; context.Configuration.ValidateOnSaveEnabled = validateOnSaveEnabled; try { context.Configuration.ValidateOnSaveEnabled = validateOnSaveEnabled; return(context.SaveChanges()); } finally { context.Configuration.ValidateOnSaveEnabled = enabled; } }
public static bool Save(System.Data.Entity.DbContext context) { try { context.SaveChanges(); return(true); } catch (System.Data.Entity.Infrastructure.DbUpdateConcurrencyException ex) { ex.Entries.Single().Reload(); } catch (Exception) { throw; } return(false); }
public override void Save(System.Data.Entity.DbContext db, DbSet <DbOption> dbOptions, bool saveInstantly = false) { const string defaultValue = ""; if (TxtB.Tag != null && TxtB.Tag.ToString() == TxtB.Text) { dbOptions.AddOrUpdate(new DbOption(Key, defaultValue)); } else { dbOptions.AddOrUpdate(new DbOption(Key, TxtB.Text ?? defaultValue)); } if (saveInstantly) { db.SaveChanges(); } }
public void Grabar() { _context.SaveChanges(); }
virtual public void Commit() { DataContext.SaveChanges(); }
protected void Save() { dbContext.SaveChanges(); }
public void Update(T item) { ctx.Entry(item).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); }
public void Add(EduAnswerEntity entity) { eduAnswerEntities.Add(entity); _context.SaveChanges(); }
public int SaveChanges() { return(_dbContext.SaveChanges()); }
public void Insert(T entity) { db.Entry(entity).State = EntityState.Added; db.SaveChanges(); }
/// <summary> /// This deletes the object and commits the deletion immediately. We don't want to delay deletion /// until a transaction commits, as it may throw a foreign key constraint exception which we could /// likely handle and inform the user about. Accordingly, this tries to delete right away; if there /// is a foreign key constraint preventing the deletion, an exception will be thrown. /// </summary> /// <param name="entity"> /// The entity. /// </param> public virtual void Delete(T entity) { _dbContext.Set <T>().Remove(entity); _dbContext.SaveChanges(); }