Пример #1
0
        public void StringNullToEmpty()
        {
            using (var fsql = new FreeSql.FreeSqlBuilder()
                              .UseConnectionString(FreeSql.DataType.Oracle, "user id=1user;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=5;min pool size=1")
                              .UseAutoSyncStructure(true)
                              //.UseGenerateCommandParameterWithLambda(true)
                              .UseLazyLoading(true)
                              .UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)
                              //.UseNoneCommandParameter(true)

                              .UseMonitorCommand(
                       cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText) //监听SQL命令对象,在执行前
                       //, (cmd, traceLog) => Console.WriteLine(traceLog)
                       )
                              .Build())
            {
                var repo = fsql.GetRepository <TS_SL361, long>();

                var item1 = new TS_SL361 {
                    CreatorId = ""
                };
                repo.Insert(item1);
                var item2 = repo.Get(item1.Id);

                Assert.Null(item2.CreatorId);

                fsql.Aop.AuditDataReader += (_, e) =>
                {
                    if (e.DataReader.GetFieldType(e.Index) == typeof(string) && e.Value == DBNull.Value)
                    {
                        e.Value = "";
                    }
                };

                item1 = new TS_SL361 {
                    CreatorId = ""
                };
                repo.Insert(item1);
                item2 = repo.Get(item1.Id);

                Assert.Equal(item1.CreatorId, item2.CreatorId);

                fsql.Aop.AuditDataReader -= fsql.Aop.AuditDataReaderHandler;

                item1 = new TS_SL361 {
                    CreatorId = ""
                };
                repo.Insert(item1);
                item2 = repo.Get(item1.Id);

                Assert.Null(item2.CreatorId);
            }
        }
Пример #2
0
        /// <summary>
        /// 生成种子数据
        /// </summary>
        public void GenerateSeedData()
        {
            IFreeSql fsql = new FreeSql.FreeSqlBuilder()
                            .UseConnectionString(FreeSql.DataType.MySql, "Server=localhost; Port=3306; Database=Tenant1db; Uid=root; Pwd=000000; Charset=utf8mb4;")
                            .Build();

            var sysApiEntities                  = fsql.GetRepository <SysApiEntity>().Select.Where(x => x.IsDeleted == false).ToList();
            var SysConditionEntities            = fsql.GetRepository <SysConditionEntity>().Select.Where(x => x.IsDeleted == false).ToList();
            var SysDictionaryDetailEntities     = fsql.GetRepository <DictionaryEntryEntity>().Select.Where(x => x.IsDeleted == false).ToList();
            var SysDictionaryEntities           = fsql.GetRepository <DictionaryHeaderEntity>().Select.Where(x => x.IsDeleted == false).ToList();
            var SysGroupEntities                = fsql.GetRepository <SysGroupEntity>().Select.Where(x => x.IsDeleted == false).ToList();
            var SysPermissionEntities           = fsql.GetRepository <SysPermissionEntity>().Select.Where(x => x.IsDeleted == false).ToList();
            var SysResourceEntities             = fsql.GetRepository <SysResourceEntity>().Select.Where(x => x.IsDeleted == false).ToList();
            var SysRoleEntities                 = fsql.GetRepository <SysRoleEntity>().Select.Where(x => x.IsDeleted == false).ToList();
            var SysRPermissionConditionEntities = fsql.GetRepository <SysRPermissionConditionEntity>().Select.ToList();
            var SysRPermissionRoleEntities      = fsql.GetRepository <SysRPermissionRoleEntity>().Select.ToList();
            var SysRResourceApiEntities         = fsql.GetRepository <SysRResourceApiEntity>().Select.ToList();
            var SysRRoleResourceEntities        = fsql.GetRepository <SysRRoleResourceEntity>().Select.ToList();
            var SysSettingEntities              = fsql.GetRepository <SysSettingEntity>().Select.Where(x => x.IsDeleted == false).ToList();
            var SysUserEntities                 = fsql.GetRepository <SysUserEntity>().Select.Where(x => x.IsDeleted == false).ToList();

            SeedDataEntity seedDataEntity = new SeedDataEntity()
            {
                SysApiEntities                  = sysApiEntities,
                SysConditionEntities            = SysConditionEntities,
                SysDictionaryEntryEntities      = SysDictionaryDetailEntities,
                SysDictionaryHeaderEntities     = SysDictionaryEntities,
                SysGroupEntities                = SysGroupEntities,
                SysPermissionEntities           = SysPermissionEntities,
                SysResourceEntities             = SysResourceEntities,
                SysRoleEntities                 = SysRoleEntities,
                SysRPermissionConditionEntities = SysRPermissionConditionEntities,
                SysRPermissionRoleEntities      = SysRPermissionRoleEntities,
                SysRResourceApiEntities         = SysRResourceApiEntities,
                SysRRoleResourceEntities        = SysRRoleResourceEntities,
                SysSettingEntities              = SysSettingEntities,
                SysUserEntities                 = SysUserEntities
            };


            WriteSeedData(seedDataEntity);


            fsql.Dispose();
        }