mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 03:53:21 +08:00
- 修复 3.2.670 中 UseNameConvert 无效;#1270
This commit is contained in:
parent
9f80879d68
commit
bc98f167e9
119
FreeSql.Tests/FreeSql.Tests/Issues/1270.cs
Normal file
119
FreeSql.Tests/FreeSql.Tests/Issues/1270.cs
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using FreeSql.Internal;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FreeSql.Tests.Issues
|
||||||
|
{
|
||||||
|
public class _1270
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void UseNameConvert()
|
||||||
|
{
|
||||||
|
using (var fsql = new FreeSqlBuilder()
|
||||||
|
.UseConnectionString(DataType.Sqlite, "Data Source=:memory:")
|
||||||
|
.UseNameConvert(NameConvertType.None)
|
||||||
|
.UseAutoSyncStructure(true)
|
||||||
|
.Build())
|
||||||
|
{
|
||||||
|
var ddl = fsql.CodeFirst.GetComparisonDDLStatements<SysUser>();
|
||||||
|
Assert.Equal(@"CREATE TABLE IF NOT EXISTS ""main"".""SysUser"" (
|
||||||
|
""Id"" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
""UserName"" NVARCHAR(255)
|
||||||
|
)
|
||||||
|
;
|
||||||
|
", ddl);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var fsql = new FreeSqlBuilder()
|
||||||
|
.UseConnectionString(DataType.Sqlite, "Data Source=:memory:")
|
||||||
|
.UseNameConvert(NameConvertType.PascalCaseToUnderscore)
|
||||||
|
.UseAutoSyncStructure(true)
|
||||||
|
.Build())
|
||||||
|
{
|
||||||
|
fsql.CodeFirst.ConfigEntity<SysUser>(a => { });
|
||||||
|
var ddl = fsql.CodeFirst.GetComparisonDDLStatements<SysUser>();
|
||||||
|
Assert.Equal(@"CREATE TABLE IF NOT EXISTS ""main"".""Sys_User"" (
|
||||||
|
""Id"" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
""User_Name"" NVARCHAR(255)
|
||||||
|
)
|
||||||
|
;
|
||||||
|
", ddl);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var fsql = new FreeSqlBuilder()
|
||||||
|
.UseConnectionString(DataType.Sqlite, "Data Source=:memory:")
|
||||||
|
.UseNameConvert(NameConvertType.PascalCaseToUnderscoreWithLower)
|
||||||
|
.UseAutoSyncStructure(true)
|
||||||
|
.Build())
|
||||||
|
{
|
||||||
|
fsql.CodeFirst.ConfigEntity<SysUser>(a => { });
|
||||||
|
var ddl = fsql.CodeFirst.GetComparisonDDLStatements<SysUser>();
|
||||||
|
Assert.Equal(@"CREATE TABLE IF NOT EXISTS ""main"".""sys_user"" (
|
||||||
|
""id"" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
""user_name"" NVARCHAR(255)
|
||||||
|
)
|
||||||
|
;
|
||||||
|
", ddl);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var fsql = new FreeSqlBuilder()
|
||||||
|
.UseConnectionString(DataType.Sqlite, "Data Source=:memory:")
|
||||||
|
.UseNameConvert(NameConvertType.PascalCaseToUnderscoreWithUpper)
|
||||||
|
.UseAutoSyncStructure(true)
|
||||||
|
.Build())
|
||||||
|
{
|
||||||
|
fsql.CodeFirst.ConfigEntity<SysUser>(a => { });
|
||||||
|
var ddl = fsql.CodeFirst.GetComparisonDDLStatements<SysUser>();
|
||||||
|
Assert.Equal(@"CREATE TABLE IF NOT EXISTS ""main"".""SYS_USER"" (
|
||||||
|
""ID"" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
""USER_NAME"" NVARCHAR(255)
|
||||||
|
)
|
||||||
|
;
|
||||||
|
", ddl);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var fsql = new FreeSqlBuilder()
|
||||||
|
.UseConnectionString(DataType.Sqlite, "Data Source=:memory:")
|
||||||
|
.UseNameConvert(NameConvertType.ToLower)
|
||||||
|
.UseAutoSyncStructure(true)
|
||||||
|
.Build())
|
||||||
|
{
|
||||||
|
fsql.CodeFirst.ConfigEntity<SysUser>(a => { });
|
||||||
|
var ddl = fsql.CodeFirst.GetComparisonDDLStatements<SysUser>();
|
||||||
|
Assert.Equal(@"CREATE TABLE IF NOT EXISTS ""main"".""sysuser"" (
|
||||||
|
""id"" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
""username"" NVARCHAR(255)
|
||||||
|
)
|
||||||
|
;
|
||||||
|
", ddl);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var fsql = new FreeSqlBuilder()
|
||||||
|
.UseConnectionString(DataType.Sqlite, "Data Source=:memory:")
|
||||||
|
.UseNameConvert(NameConvertType.ToUpper)
|
||||||
|
.UseAutoSyncStructure(true)
|
||||||
|
.Build())
|
||||||
|
{
|
||||||
|
fsql.CodeFirst.ConfigEntity<SysUser>(a => { });
|
||||||
|
var ddl = fsql.CodeFirst.GetComparisonDDLStatements<SysUser>();
|
||||||
|
Assert.Equal(@"CREATE TABLE IF NOT EXISTS ""main"".""SYSUSER"" (
|
||||||
|
""ID"" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
""USERNAME"" NVARCHAR(255)
|
||||||
|
)
|
||||||
|
;
|
||||||
|
", ddl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SysUser
|
||||||
|
{
|
||||||
|
[Column(IsPrimary = true, IsIdentity = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string UserName { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -128,7 +128,7 @@ namespace FreeSql.Internal
|
|||||||
{
|
{
|
||||||
ModifyResult = new TableAttribute
|
ModifyResult = new TableAttribute
|
||||||
{
|
{
|
||||||
Name = attr.Name,
|
Name = attr.Name ?? type.Name,
|
||||||
OldName = attr.OldName,
|
OldName = attr.OldName,
|
||||||
_DisableSyncStructure = attr._DisableSyncStructure,
|
_DisableSyncStructure = attr._DisableSyncStructure,
|
||||||
AsTable = attr.AsTable
|
AsTable = attr.AsTable
|
||||||
@ -136,7 +136,7 @@ namespace FreeSql.Internal
|
|||||||
};
|
};
|
||||||
_orm.Aop.ConfigEntityHandler(_orm, aope);
|
_orm.Aop.ConfigEntityHandler(_orm, aope);
|
||||||
var tryattr = aope.ModifyResult;
|
var tryattr = aope.ModifyResult;
|
||||||
if (!string.IsNullOrEmpty(tryattr.Name)) attr.Name = tryattr.Name;
|
if (!string.IsNullOrEmpty(tryattr.Name) && tryattr.Name != type.Name) attr.Name = tryattr.Name;
|
||||||
if (!string.IsNullOrEmpty(tryattr.OldName)) attr.OldName = tryattr.OldName;
|
if (!string.IsNullOrEmpty(tryattr.OldName)) attr.OldName = tryattr.OldName;
|
||||||
if (tryattr._DisableSyncStructure != null) attr._DisableSyncStructure = tryattr.DisableSyncStructure;
|
if (tryattr._DisableSyncStructure != null) attr._DisableSyncStructure = tryattr.DisableSyncStructure;
|
||||||
if (!string.IsNullOrEmpty(tryattr.AsTable)) attr.AsTable = tryattr.AsTable;
|
if (!string.IsNullOrEmpty(tryattr.AsTable)) attr.AsTable = tryattr.AsTable;
|
||||||
@ -194,7 +194,7 @@ namespace FreeSql.Internal
|
|||||||
{
|
{
|
||||||
ModifyResult = new ColumnAttribute
|
ModifyResult = new ColumnAttribute
|
||||||
{
|
{
|
||||||
Name = attr.Name,
|
Name = attr.Name ?? proto.Name,
|
||||||
OldName = attr.OldName,
|
OldName = attr.OldName,
|
||||||
DbType = attr.DbType,
|
DbType = attr.DbType,
|
||||||
_IsPrimary = attr._IsPrimary,
|
_IsPrimary = attr._IsPrimary,
|
||||||
@ -217,7 +217,7 @@ namespace FreeSql.Internal
|
|||||||
};
|
};
|
||||||
_orm.Aop.ConfigEntityPropertyHandler(_orm, aope);
|
_orm.Aop.ConfigEntityPropertyHandler(_orm, aope);
|
||||||
var tryattr = aope.ModifyResult;
|
var tryattr = aope.ModifyResult;
|
||||||
if (!string.IsNullOrEmpty(tryattr.Name)) attr.Name = tryattr.Name;
|
if (!string.IsNullOrEmpty(tryattr.Name) && tryattr.Name != proto.Name) attr.Name = tryattr.Name;
|
||||||
if (!string.IsNullOrEmpty(tryattr.OldName)) attr.OldName = tryattr.OldName;
|
if (!string.IsNullOrEmpty(tryattr.OldName)) attr.OldName = tryattr.OldName;
|
||||||
if (!string.IsNullOrEmpty(tryattr.DbType)) attr.DbType = tryattr.DbType;
|
if (!string.IsNullOrEmpty(tryattr.DbType)) attr.DbType = tryattr.DbType;
|
||||||
if (tryattr._IsPrimary != null) attr._IsPrimary = tryattr.IsPrimary;
|
if (tryattr._IsPrimary != null) attr._IsPrimary = tryattr.IsPrimary;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user