mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
## v0.3.26
- 修复 SqlServer CodeFirst 迁移多主键的 bug #23;
This commit is contained in:
parent
c4c1057294
commit
025259bb81
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
<Version>0.3.25</Version>
|
<Version>0.3.216</Version>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<Authors>YeXiangQin</Authors>
|
<Authors>YeXiangQin</Authors>
|
||||||
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>
|
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
<Version>0.3.25</Version>
|
<Version>0.3.26</Version>
|
||||||
<Authors>YeXiangQin</Authors>
|
<Authors>YeXiangQin</Authors>
|
||||||
<Description>FreeSql Implementation of General Repository, Support MySql/SqlServer/PostgreSQL/Oracle/Sqlite, and read/write separation、and split table.</Description>
|
<Description>FreeSql Implementation of General Repository, Support MySql/SqlServer/PostgreSQL/Oracle/Sqlite, and read/write separation、and split table.</Description>
|
||||||
<PackageProjectUrl>https://github.com/2881099/FreeSql/wiki/Repository</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/2881099/FreeSql/wiki/Repository</PackageProjectUrl>
|
||||||
|
@ -5,10 +5,7 @@ using Xunit;
|
|||||||
namespace FreeSql.Tests.DataAnnotations {
|
namespace FreeSql.Tests.DataAnnotations {
|
||||||
public class MySqlFluentTest {
|
public class MySqlFluentTest {
|
||||||
|
|
||||||
SqlServerFixture _sqlserverFixture;
|
public MySqlFluentTest() {
|
||||||
|
|
||||||
public MySqlFluentTest(SqlServerFixture sqlserverFixture) {
|
|
||||||
_sqlserverFixture = sqlserverFixture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -44,15 +41,6 @@ namespace FreeSql.Tests.DataAnnotations {
|
|||||||
var t2 = g.mysql.Select<TestFluenttb2>(t2lastId + 1).ToOne();
|
var t2 = g.mysql.Select<TestFluenttb2>(t2lastId + 1).ToOne();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void GroupPrimaryKey() {
|
|
||||||
_sqlserverFixture.SqlServer.CodeFirst.SyncStructure<TestgroupkeyTb>();
|
|
||||||
g.mysql.CodeFirst.SyncStructure<TestgroupkeyTb>();
|
|
||||||
g.pgsql.CodeFirst.SyncStructure<TestgroupkeyTb>();
|
|
||||||
g.sqlite.CodeFirst.SyncStructure<TestgroupkeyTb>();
|
|
||||||
g.oracle.CodeFirst.SyncStructure<TestgroupkeyTb>();
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestFluenttb1
|
class TestFluenttb1
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
@ -66,17 +54,6 @@ namespace FreeSql.Tests.DataAnnotations {
|
|||||||
[Column(Name = "Idx", IsPrimary = true, IsIdentity = false)]
|
[Column(Name = "Idx", IsPrimary = true, IsIdentity = false)]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
public string name { get; set; } = "defaultValue";
|
|
||||||
}
|
|
||||||
|
|
||||||
[Table(Name = "test_groupkey")]
|
|
||||||
class TestgroupkeyTb {
|
|
||||||
[Column(IsPrimary = true)]
|
|
||||||
public int Id { get; set; }
|
|
||||||
[Column(IsPrimary = true)]
|
|
||||||
public int id2 { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
public string name { get; set; } = "defaultValue";
|
public string name { get; set; } = "defaultValue";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,15 @@ namespace FreeSql.Tests.DataAnnotations {
|
|||||||
var t2 = _sqlserverFixture.SqlServer.Select<TestFluenttb2>(t2lastId + 1).ToOne();
|
var t2 = _sqlserverFixture.SqlServer.Select<TestFluenttb2>(t2lastId + 1).ToOne();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GroupPrimaryKey() {
|
||||||
|
_sqlserverFixture.SqlServer.CodeFirst.SyncStructure<TestgroupkeyTb>();
|
||||||
|
g.mysql.CodeFirst.SyncStructure<TestgroupkeyTb>();
|
||||||
|
g.pgsql.CodeFirst.SyncStructure<TestgroupkeyTb>();
|
||||||
|
g.sqlite.CodeFirst.SyncStructure<TestgroupkeyTb>();
|
||||||
|
g.oracle.CodeFirst.SyncStructure<TestgroupkeyTb>();
|
||||||
|
}
|
||||||
|
|
||||||
class TestFluenttb1
|
class TestFluenttb1
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
@ -59,6 +68,17 @@ namespace FreeSql.Tests.DataAnnotations {
|
|||||||
[Column(Name = "Idx", IsPrimary = true, IsIdentity = false)]
|
[Column(Name = "Idx", IsPrimary = true, IsIdentity = false)]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string name { get; set; } = "defaultValue";
|
||||||
|
}
|
||||||
|
|
||||||
|
[Table(Name = "test_groupkey")]
|
||||||
|
class TestgroupkeyTb {
|
||||||
|
[Column(IsPrimary = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Column(IsPrimary = true)]
|
||||||
|
public int id2 { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public string name { get; set; } = "defaultValue";
|
public string name { get; set; } = "defaultValue";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
<Version>0.3.25</Version>
|
<Version>0.3.26</Version>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<Authors>YeXiangQin</Authors>
|
<Authors>YeXiangQin</Authors>
|
||||||
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>
|
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>
|
||||||
|
@ -124,11 +124,19 @@ namespace FreeSql.SqlServer {
|
|||||||
if (tboldname == null) {
|
if (tboldname == null) {
|
||||||
//创建新表
|
//创建新表
|
||||||
sb.Append("use ").Append(_commonUtils.QuoteSqlName(tbname[0])).Append(";\r\nCREATE TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[1]}.{tbname[2]}")).Append(" (");
|
sb.Append("use ").Append(_commonUtils.QuoteSqlName(tbname[0])).Append(";\r\nCREATE TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[1]}.{tbname[2]}")).Append(" (");
|
||||||
|
var pkidx = 0;
|
||||||
foreach (var tbcol in tb.Columns.Values) {
|
foreach (var tbcol in tb.Columns.Values) {
|
||||||
sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ");
|
sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ");
|
||||||
sb.Append(tbcol.Attribute.DbType);
|
sb.Append(tbcol.Attribute.DbType);
|
||||||
if (tbcol.Attribute.IsIdentity == true && tbcol.Attribute.DbType.IndexOf("identity", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" identity(1,1)");
|
if (tbcol.Attribute.IsIdentity == true && tbcol.Attribute.DbType.IndexOf("identity", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" identity(1,1)");
|
||||||
if (tbcol.Attribute.IsPrimary == true) sb.Append(" primary key");
|
if (tbcol.Attribute.IsPrimary == true) {
|
||||||
|
if (tb.Primarys.Length > 1) {
|
||||||
|
if (pkidx == tb.Primarys.Length - 1)
|
||||||
|
sb.Append(" primary key (").Append(string.Join(", ", tb.Primarys.Select(a => _commonUtils.QuoteSqlName(a.Attribute.Name)))).Append(")");
|
||||||
|
} else
|
||||||
|
sb.Append(" primary key");
|
||||||
|
pkidx++;
|
||||||
|
}
|
||||||
sb.Append(",");
|
sb.Append(",");
|
||||||
}
|
}
|
||||||
sb.Remove(sb.Length - 1, 1).Append("\r\n);\r\n");
|
sb.Remove(sb.Length - 1, 1).Append("\r\n);\r\n");
|
||||||
@ -220,11 +228,19 @@ use " + database, tboldname ?? tbname);
|
|||||||
sb.Append("BEGIN TRANSACTION;\r\n");
|
sb.Append("BEGIN TRANSACTION;\r\n");
|
||||||
//创建临时表
|
//创建临时表
|
||||||
sb.Append("CREATE TABLE ").Append(tmptablename).Append(" (");
|
sb.Append("CREATE TABLE ").Append(tmptablename).Append(" (");
|
||||||
|
var pkidx2 = 0;
|
||||||
foreach (var tbcol in tb.Columns.Values) {
|
foreach (var tbcol in tb.Columns.Values) {
|
||||||
sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ");
|
sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ");
|
||||||
sb.Append(tbcol.Attribute.DbType);
|
sb.Append(tbcol.Attribute.DbType);
|
||||||
if (tbcol.Attribute.IsIdentity == true && tbcol.Attribute.DbType.IndexOf("identity", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" identity(1,1)");
|
if (tbcol.Attribute.IsIdentity == true && tbcol.Attribute.DbType.IndexOf("identity", StringComparison.CurrentCultureIgnoreCase) == -1) sb.Append(" identity(1,1)");
|
||||||
if (tbcol.Attribute.IsPrimary == true) sb.Append(" primary key");
|
if (tbcol.Attribute.IsPrimary == true) {
|
||||||
|
if (tb.Primarys.Length > 1) {
|
||||||
|
if (pkidx2 == tb.Primarys.Length - 1)
|
||||||
|
sb.Append(" primary key (").Append(string.Join(", ", tb.Primarys.Select(a => _commonUtils.QuoteSqlName(a.Attribute.Name)))).Append(")");
|
||||||
|
} else
|
||||||
|
sb.Append(" primary key");
|
||||||
|
pkidx2++;
|
||||||
|
}
|
||||||
sb.Append(",");
|
sb.Append(",");
|
||||||
idents = idents || tbcol.Attribute.IsIdentity == true;
|
idents = idents || tbcol.Attribute.IsIdentity == true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user