示例#1
0
        /// <summary>
        /// 保存或者更新一条记录(速度慢)
        /// 默认使用混合模式
        /// </summary>
        /// <param name="mode">INSERT,UPDATE,MIXED</param>
        /// <param name="tableName">另外指定表名</param>
        /// <param name="args"></param>
        public override void Save(EntitySaveMode mode = EntitySaveMode.MIXED, String tableName = null)
        {
            if (tableName != null && tableName.EndsWith("Entity") && tableName != "Entity")
            {
                if (tableName.EndsWith("_Entity"))
                {
                    tableName = tableName.Remove(tableName.Length - "_Entity".Length, "_Entity".Length);
                }
                if (tableName.EndsWith("Entity"))
                {
                    tableName = tableName.Remove(tableName.Length - "Entity".Length, "Entity".Length);
                }
            }
            this.TableName = tableName;
            switch (mode)
            {
            case EntitySaveMode.INSERT:
                ex = OrmHost?.ISave(this);
                break;

            case EntitySaveMode.UPDATE:
                ex = OrmHost?.USave(this);
                break;

            case EntitySaveMode.MIXED:
                ex = OrmHost?.Save(this);
                break;
            }

            TableName = null;
        }
示例#2
0
        /// <summary>
        /// 保存或者更新一条记录(速度慢)
        /// 对于日志保存不需要指定日志表名
        /// 默认使用混合模式
        /// </summary>
        /// <param name="mode">INSERT,UPDATE,MIXED</param>
        /// <param name="tableName">另外指定表名</param>
        /// <param name="args"></param>
        public override void Save(EntitySaveMode mode = EntitySaveMode.MIXED, String tableName = null)
        {
            lock (OrmHost)
            {
                try
                {
                    if (tableName != null && tableName.EndsWith("Entity") && tableName != "Entity")
                    {
                        if (tableName.EndsWith("_Entity"))
                        {
                            tableName = tableName.Remove(tableName.Length - "_Entity".Length, "_Entity".Length);
                        }
                        if (tableName.EndsWith("Entity"))
                        {
                            tableName = tableName.Remove(tableName.Length - "Entity".Length, "Entity".Length);
                        }
                    }


                    this.TableName = tableName;
                    if (TableName == null)
                    {
                        string formatedTimeString = LogFiredTime.ToString("yyyy-MM-dd HH:mm:ss");
                        String msgContent         = String.Format("{0} {1} {2}\r\n", formatedTimeString
                                                                  , Status, Message);
                        Console.WriteLine(msgContent);
                        String _tableName = String.Format("_{0}_Log", DateTime.Now.ToString("yyyy_MM"));
                        TableName = _tableName;

                        if (!Directory.Exists(LogFileDirPath))
                        {
                            Directory.CreateDirectory(LogFileDirPath);
                        }
                        String txtLogFilePath = Path.Combine(LogFileDirPath, TableName + ".txt");

                        File.AppendAllText(txtLogFilePath, msgContent);
                        OrmHost.AddTable(typeof(AppLogEntity), TableName, false);
                    }

                    switch (mode)
                    {
                    case EntitySaveMode.INSERT:
                        OrmHost?.ISave(this);
                        break;

                    case EntitySaveMode.UPDATE:
                        OrmHost?.USave(this);
                        break;

                    case EntitySaveMode.MIXED:
                        OrmHost?.Save(this);
                        break;
                    }

                    TableName = null;
                }
                catch (Exception ex)
                {
                }
            }
        }