/// <summary> /// 写数据 /// </summary> /// <param name="queueGroup"></param> private void WriteData(QueueGroup queueGroup) { try { foreach (var key in queueGroup.QueueDic.Keys) {//TODO:根据类型获取表名 if (!_tableList.Contains(Class2DbHelper.Instance[key].ClassAttribute.TableName)) { //创建表 CreateTable(key); _tableList.Add(Class2DbHelper.Instance[key].ClassAttribute.TableName); } //插入数据 int queueCurrentCount = queueGroup.QueueDic[key].Count; if (queueCurrentCount > 0) { SqliteContext sqliteContext = new SqliteContext(new DBContextBridge { ConnectionString = _connStr, Provider = "sqlite", }); int transid = 0; for (int i = 0; i < queueCurrentCount; i++) { if (transid == 0) { transid = sqliteContext.RegisteTrans(); } var entity = queueGroup.QueueDic[key].Dequeue() as SqliteEntity; if (entity != null) { //string opid = entity.GetValue(entity, "ContentOpid").ToString(); //string domainId = entity.GetValue(entity, "DomainId").ToString(); //string createTime = entity.GetValue(entity, "CreateTime").ToString(); //Logger.WriteError("输出GetValue", string.Format("ContentOpid:{0},DomainId:{1},CreateTime:{2}", opid, domainId, createTime)); sqliteContext.ExecuteSQL(transid, Class2DbHelper.Instance[key].GetInsertSqliteSql(entity)); if ((i > 0 && i % 10000 == 0) || i == queueCurrentCount - 1) { sqliteContext.TransCommit(transid); transid = 0; } } } } } } catch (Exception ex) { throw new ApplicationException("写sqlite数据时出现异常", ex); } }