mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 修复ClickHouse CodeFirst 多主键问题
This commit is contained in:
parent
c9aa3353fb
commit
eec10f89b0
@ -23,5 +23,126 @@ namespace FreeSql.Tests.ClickHouse
|
||||
{
|
||||
fsql.CodeFirst.SyncStructure(typeof(CollectDataEntityUpdate01));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Issuse1587Test()
|
||||
{
|
||||
fsql.CodeFirst.SyncStructure(typeof(PositionInfoModel));
|
||||
}
|
||||
[Fact]
|
||||
public void Issuse1587TestOnePrimary()
|
||||
{
|
||||
fsql.CodeFirst.SyncStructure(typeof(PositionInfoModel2));
|
||||
}
|
||||
}
|
||||
|
||||
[Table(Name = "table_1")]
|
||||
[Index("stcd_index", "STCD", false)]
|
||||
[Index("tm_index", "TM", false)]
|
||||
[Index("type_index", "TYPE", false)]
|
||||
public class PositionInfoModel
|
||||
{
|
||||
[Column(IsPrimary = true)]
|
||||
public string STCD
|
||||
{
|
||||
set; get;
|
||||
}
|
||||
|
||||
[Column(IsPrimary = true)]
|
||||
public DateTime TM
|
||||
{
|
||||
set; get;
|
||||
}
|
||||
|
||||
[Column(IsNullable = false)]
|
||||
public decimal LON
|
||||
{
|
||||
set; get;
|
||||
}
|
||||
|
||||
[Column(IsNullable = false)]
|
||||
public decimal LAT
|
||||
{
|
||||
set; get;
|
||||
}
|
||||
|
||||
[Column(IsNullable = false)]
|
||||
public int TYPE
|
||||
{
|
||||
set; get;
|
||||
}
|
||||
|
||||
[Column(IsNullable = true)]
|
||||
public decimal SPD
|
||||
{
|
||||
set; get;
|
||||
}
|
||||
|
||||
[Column(IsNullable = true)]
|
||||
public decimal COG
|
||||
{
|
||||
set; get;
|
||||
}
|
||||
|
||||
[Column(IsNullable = true)]
|
||||
public DateTime? UT
|
||||
{
|
||||
set; get;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Table(Name = "table_2")]
|
||||
[Index("stcd_index", "STCD", false)]
|
||||
[Index("tm_index", "TM", false)]
|
||||
[Index("type_index", "TYPE", false)]
|
||||
public class PositionInfoModel2
|
||||
{
|
||||
public string STCD
|
||||
{
|
||||
set; get;
|
||||
}
|
||||
|
||||
[Column(IsPrimary = true)]
|
||||
public DateTime TM
|
||||
{
|
||||
set; get;
|
||||
}
|
||||
|
||||
[Column(IsNullable = false)]
|
||||
public decimal LON
|
||||
{
|
||||
set; get;
|
||||
}
|
||||
|
||||
[Column(IsNullable = false)]
|
||||
public decimal LAT
|
||||
{
|
||||
set; get;
|
||||
}
|
||||
|
||||
[Column(IsNullable = false)]
|
||||
public int TYPE
|
||||
{
|
||||
set; get;
|
||||
}
|
||||
|
||||
[Column(IsNullable = true)]
|
||||
public decimal SPD
|
||||
{
|
||||
set; get;
|
||||
}
|
||||
|
||||
[Column(IsNullable = true)]
|
||||
public decimal COG
|
||||
{
|
||||
set; get;
|
||||
}
|
||||
|
||||
[Column(IsNullable = true)]
|
||||
public DateTime? UT
|
||||
{
|
||||
set; get;
|
||||
}
|
||||
}
|
||||
}
|
@ -199,7 +199,7 @@ namespace FreeSql.ClickHouse
|
||||
sb.Remove(sb.Length - 2, 2);
|
||||
sb.Append(" )");
|
||||
sb.Append(" \r\nPRIMARY KEY ");
|
||||
sb.Append(ls);
|
||||
sb.Append($"({ls}) ");
|
||||
sb.Remove(sb.Length - 2, 2).Append(",");
|
||||
}
|
||||
|
||||
@ -415,7 +415,7 @@ where a.database in ({0}) and a.table in ({1})", tboldname ?? tbname);
|
||||
sb.Remove(sb.Length - 2, 2);
|
||||
sb.Append(" )");
|
||||
sb.Append(" \r\nPRIMARY KEY ");
|
||||
sb.Append(ls);
|
||||
sb.Append($"({ls}) ");
|
||||
sb.Remove(sb.Length - 2, 2).Append(",");
|
||||
}
|
||||
|
||||
@ -455,7 +455,8 @@ where a.database in ({0}) and a.table in ({1})", tboldname ?? tbname);
|
||||
.Append(_commonUtils.QuoteSqlName(tbname[0], tbname[1])).Append(";\r\n");
|
||||
}
|
||||
|
||||
return sb.Length == 0 ? null : sb.ToString();
|
||||
var res = sb.Length == 0 ? null : sb.ToString();
|
||||
return res;
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -514,9 +515,14 @@ where a.database in ({0}) and a.table in ({1})", tboldname ?? tbname);
|
||||
}
|
||||
string CkNullableAdapter(string dbType, bool isPrimary)
|
||||
{
|
||||
return isPrimary
|
||||
? dbType.Replace("Nullable(", "").Replace(")","").Replace(" NOT NULL", "")
|
||||
: dbType.Replace(" NOT NULL", "");
|
||||
return isPrimary switch
|
||||
{
|
||||
true when dbType.Contains("Nullable") => dbType.Replace("Nullable(", "")
|
||||
.Replace(")", "")
|
||||
.Replace(" NOT NULL", ""),
|
||||
true => dbType,
|
||||
_ => dbType.Replace(" NOT NULL", "")
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user