Skip to content

Commit

Permalink
- 优化 DbFirst 模式长内容未设置 StringLength = -1 写入问题;
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Dec 2, 2020
1 parent 4358566 commit e61a50c
Show file tree
Hide file tree
Showing 19 changed files with 282 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,31 @@ namespace FreeSql.Tests.MySqlConnector
{
public class MySqlCodeFirstTest
{
[Fact]
public void InsertUpdateParameter()
{
var fsql = g.mysql;
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(find.id, item.id);
Assert.Equal(find.title, item.title);
}
[Table(Name = "ts_iupstr_bak", DisableSyncStructure = true)]
class ts_iupstr
{
public Guid id { get; set; }
public string title { get; set; }
}
class ts_iupstr_bak
{
public Guid id { get; set; }
[Column(StringLength = -1)]
public string title { get; set; }
}

[Fact]
public void Timestamp01()
{
Expand Down
25 changes: 25 additions & 0 deletions FreeSql.Tests/FreeSql.Tests/Dameng/DamengCodeFirstTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,31 @@ namespace FreeSql.Tests.Dameng
{
public class DamengCodeFirstTest
{
[Fact]
public void InsertUpdateParameter()
{
var fsql = g.dameng;
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(find.id, item.id);
Assert.Equal(find.title, item.title);
}
[Table(Name = "ts_iupstr_bak", DisableSyncStructure = true)]
class ts_iupstr
{
public Guid id { get; set; }
public string title { get; set; }
}
class ts_iupstr_bak
{
public Guid id { get; set; }
[Column(StringLength = -1)]
public string title { get; set; }
}

[Fact]
public void StringLength36()
{
Expand Down
25 changes: 25 additions & 0 deletions FreeSql.Tests/FreeSql.Tests/Firebird/FirebirdCodeFirstTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,31 @@ namespace FreeSql.Tests.Firebird
{
public class FirebirdCodeFirstTest
{
[Fact]
public void InsertUpdateParameter()
{
var fsql = g.firebird;
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(find.id, item.id);
Assert.Equal(find.title, item.title);
}
[Table(Name = "ts_iupstr_bak", DisableSyncStructure = true)]
class ts_iupstr
{
public Guid id { get; set; }
public string title { get; set; }
}
class ts_iupstr_bak
{
public Guid id { get; set; }
[Column(StringLength = -1)]
public string title { get; set; }
}

[Fact]
public void Text_StringLength_1()
{
Expand Down
25 changes: 25 additions & 0 deletions FreeSql.Tests/FreeSql.Tests/KingbaseES/KingbaseESCodeFirstTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,31 @@ namespace FreeSql.Tests.KingbaseES
{
public class KingbaseESCodeFirstTest
{
[Fact]
public void InsertUpdateParameter()
{
var fsql = g.kingbaseES;
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(find.id, item.id);
Assert.Equal(find.title, item.title);
}
[Table(Name = "ts_iupstr_bak", DisableSyncStructure = true)]
class ts_iupstr
{
public Guid id { get; set; }
public string title { get; set; }
}
class ts_iupstr_bak
{
public Guid id { get; set; }
[Column(StringLength = -1)]
public string title { get; set; }
}

[Fact]
public void StringLength()
{
Expand Down
25 changes: 25 additions & 0 deletions FreeSql.Tests/FreeSql.Tests/MsAccess/MsAccessCodeFirstTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,31 @@ namespace FreeSql.Tests.MsAccess
{
public class MsAccessCodeFirstTest
{
[Fact]
public void InsertUpdateParameter()
{
var fsql = g.msaccess;
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(find.id, item.id);
Assert.Equal(find.title, item.title);
}
[Table(Name = "ts_iupstr_bak", DisableSyncStructure = true)]
class ts_iupstr
{
public Guid id { get; set; }
public string title { get; set; }
}
class ts_iupstr_bak
{
public Guid id { get; set; }
[Column(StringLength = -1)]
public string title { get; set; }
}

[Fact]
public void StringLength()
{
Expand Down
25 changes: 25 additions & 0 deletions FreeSql.Tests/FreeSql.Tests/MySql/MySqlCodeFirstTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,31 @@ namespace FreeSql.Tests.MySql
{
public class MySqlCodeFirstTest
{
[Fact]
public void InsertUpdateParameter()
{
var fsql = g.mysql;
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(find.id, item.id);
Assert.Equal(find.title, item.title);
}
[Table(Name = "ts_iupstr_bak", DisableSyncStructure = true)]
class ts_iupstr
{
public Guid id { get; set; }
public string title { get; set; }
}
class ts_iupstr_bak
{
public Guid id { get; set; }
[Column(StringLength = -1)]
public string title { get; set; }
}

[Fact]
public void Timestamp01()
{
Expand Down
25 changes: 25 additions & 0 deletions FreeSql.Tests/FreeSql.Tests/Oracle/OracleCodeFirstTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,31 @@ namespace FreeSql.Tests.Oracle
{
public class OracleCodeFirstTest
{
[Fact]
public void InsertUpdateParameter()
{
var fsql = g.oracle;
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(find.id, item.id);
Assert.Equal(find.title, item.title);
}
[Table(Name = "ts_iupstr_bak", DisableSyncStructure = true)]
class ts_iupstr
{
public Guid id { get; set; }
public string title { get; set; }
}
class ts_iupstr_bak
{
public Guid id { get; set; }
[Column(StringLength = -1)]
public string title { get; set; }
}

[Fact]
public void StringNullToEmpty()
{
Expand Down
25 changes: 25 additions & 0 deletions FreeSql.Tests/FreeSql.Tests/PostgreSQL/PostgreSQLCodeFirstTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,31 @@ namespace FreeSql.Tests.PostgreSQL
{
public class PostgreSQLCodeFirstTest
{
[Fact]
public void InsertUpdateParameter()
{
var fsql = g.pgsql;
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(find.id, item.id);
Assert.Equal(find.title, item.title);
}
[Table(Name = "ts_iupstr_bak", DisableSyncStructure = true)]
class ts_iupstr
{
public Guid id { get; set; }
public string title { get; set; }
}
class ts_iupstr_bak
{
public Guid id { get; set; }
[Column(StringLength = -1)]
public string title { get; set; }
}

[Fact]
public void DateTime_1()
{
Expand Down
24 changes: 24 additions & 0 deletions FreeSql.Tests/FreeSql.Tests/ShenTong/ShenTongCodeFirstTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@ namespace FreeSql.Tests.ShenTong
{
public class ShenTongCodeFirstTest
{
[Fact]
public void InsertUpdateParameter()
{
var fsql = g.shentong;
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(find.id, item.id);
Assert.Equal(find.title, item.title);
}
[Table(Name = "ts_iupstr_bak", DisableSyncStructure = true)]
class ts_iupstr
{
public Guid id { get; set; }
public string title { get; set; }
}
class ts_iupstr_bak
{
public Guid id { get; set; }
[Column(StringLength = -1)]
public string title { get; set; }
}

[Fact]
public void StringLength()
Expand Down
25 changes: 25 additions & 0 deletions FreeSql.Tests/FreeSql.Tests/SqlServer/SqlServerCodeFirstTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,31 @@ namespace FreeSql.Tests.SqlServer
{
public class SqlServerCodeFirstTest
{
[Fact]
public void InsertUpdateParameter()
{
var fsql = g.sqlserver;
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(find.id, item.id);
Assert.Equal(find.title, item.title);
}
[Table(Name = "ts_iupstr_bak", DisableSyncStructure = true)]
class ts_iupstr
{
public Guid id { get; set; }
public string title { get; set; }
}
class ts_iupstr_bak
{
public Guid id { get; set; }
[Column(StringLength = -1)]
public string title { get; set; }
}

[Fact]
public void EnumStartValue1()
{
Expand Down
25 changes: 25 additions & 0 deletions FreeSql.Tests/FreeSql.Tests/Sqlite/SqliteCodeFirstTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,31 @@ namespace FreeSql.Tests.Sqlite
{
public class SqliteCodeFirstTest
{
[Fact]
public void InsertUpdateParameter()
{
var fsql = g.sqlite;
fsql.CodeFirst.SyncStructure<ts_iupstr_bak>();
var item = new ts_iupstr { id = Guid.NewGuid(), title = string.Join(",", Enumerable.Range(0, 2000).Select(a => "我是中国人")) };
Assert.Equal(1, fsql.Insert(item).ExecuteAffrows());
var find = fsql.Select<ts_iupstr>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(find.id, item.id);
Assert.Equal(find.title, item.title);
}
[Table(Name = "ts_iupstr_bak", DisableSyncStructure = true)]
class ts_iupstr
{
public Guid id { get; set; }
public string title { get; set; }
}
class ts_iupstr_bak
{
public Guid id { get; set; }
[Column(StringLength = -1)]
public string title { get; set; }
}

[Fact]
public void Blob()
{
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.Dameng/DamengUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override DbParameter AppendParamter(List<DbParameter> _params, string par
{
case DmDbType.Bit:
if (value == null) value = null;
else value = (bool)value == true ? 1 : 0;
else value = (bool) value == true ? 1 : 0;
dbtype = DmDbType.Int32;
break;

Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.Firebird/FirebirdUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override DbParameter AppendParamter(List<DbParameter> _params, string par
break;
default:
dbtype = dbtype2;
if (col.DbSize != 0) ret.Size = col.DbSize;
//if (col.DbSize != 0) ret.Size = col.DbSize;
if (col.DbPrecision != 0) ret.Precision = col.DbPrecision;
if (col.DbScale != 0) ret.Scale = col.DbScale;
break;
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.MySql/MySqlUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override DbParameter AppendParamter(List<DbParameter> _params, string par
break;
default:
dbtype = dbtype2;
if (col.DbSize != 0) ret.Size = col.DbSize;
//if (col.DbSize != 0) ret.Size = col.DbSize;
if (col.DbPrecision != 0) ret.Precision = col.DbPrecision;
if (col.DbScale != 0) ret.Scale = col.DbScale;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override DbParameter AppendParamter(List<DbParameter> _params, string par
// break;
default:
dbtype = dbtype2;
if (col.DbSize != 0) ret.Size = col.DbSize;
//if (col.DbSize != 0) ret.Size = col.DbSize;
if (col.DbPrecision != 0) ret.Precision = col.DbPrecision;
if (col.DbScale != 0) ret.Scale = col.DbScale;
break;
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.Oracle/OracleUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override DbParameter AppendParamter(List<DbParameter> _params, string par
case OracleDbType.NVarchar2:
case OracleDbType.Decimal:
dbtype = dbtype2;
if (col.DbSize != 0) ret.Size = col.DbSize;
//if (col.DbSize != 0) ret.Size = col.DbSize;
if (col.DbPrecision != 0) ret.Precision = col.DbPrecision;
if (col.DbScale != 0) ret.Scale = col.DbScale;
break;
Expand Down
Loading

0 comments on commit e61a50c

Please sign in to comment.