mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 04:18:16 +08:00
- 优化 MySql StringLength/MaxLength -2 产生 LongText 映射;
This commit is contained in:
@ -10,6 +10,94 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
{
|
||||
public class MySqlCodeFirstTest
|
||||
{
|
||||
[Fact]
|
||||
public void Text_StringLength_1()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 1000).Select(a => "<22><><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><D0B9><EFBFBD>"));
|
||||
|
||||
var item1 = new TS_TEXT02 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.mysql.Select<TS_TEXT02>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT02 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT02
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(StringLength = -1)]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Text()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 1000).Select(a => "<22><><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><D0B9><EFBFBD>"));
|
||||
|
||||
var item1 = new TS_TEXT01 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.mysql.Select<TS_TEXT01>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT01 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT01
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(DbType = "text")]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Text_StringLength_2()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "<22><><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><D0B9><EFBFBD>"));
|
||||
|
||||
var item1 = new TS_TEXT04 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.mysql.Select<TS_TEXT04>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT04 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT04
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(StringLength = -2)]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LongText()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "<22><><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><D0B9><EFBFBD>"));
|
||||
|
||||
var item1 = new TS_TEXT03 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.mysql.Select<TS_TEXT03>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT03 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT03
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(DbType = "longtext")]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StringLength()
|
||||
{
|
||||
|
@ -9,7 +9,7 @@ namespace FreeSql.Tests.Dameng
|
||||
public class DamengInsertTest
|
||||
{
|
||||
|
||||
IInsert<Topic> insert => g.dameng.Insert<Topic>(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
IInsert<Topic> insert => g.dameng.Insert<Topic>().NoneParameter();
|
||||
|
||||
[Table(Name = "tb_topic_insert")]
|
||||
class Topic
|
||||
|
@ -7,7 +7,7 @@ namespace FreeSql.Tests.Dameng
|
||||
{
|
||||
public class DamengUpdateTest
|
||||
{
|
||||
IUpdate<Topic> update => g.dameng.Update<Topic>();
|
||||
IUpdate<Topic> update => g.dameng.Update<Topic>().NoneParameter();
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
|
@ -10,6 +10,74 @@ namespace FreeSql.Tests.Dameng
|
||||
{
|
||||
public class DamengCodeFirstTest
|
||||
{
|
||||
[Fact]
|
||||
public void Text_StringLength_1()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "<22><><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><D0B9><EFBFBD>"));
|
||||
|
||||
var item1 = new TS_TEXT02 { Data = str1 };
|
||||
Assert.Equal(1, g.dameng.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.dameng.Select<TS_TEXT02>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT02 { Data = str1 };
|
||||
Assert.Equal(1, g.dameng.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT02
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(StringLength = -1)]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Text()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "<22><><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><D0B9><EFBFBD>"));
|
||||
|
||||
var item1 = new TS_TEXT01 { Data = str1 };
|
||||
Assert.Equal(1, g.dameng.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.dameng.Select<TS_TEXT01>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT01 { Data = str1 };
|
||||
Assert.Equal(1, g.dameng.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT01
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(DbType = "text")]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void Blob()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "<22><><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><D0B9><EFBFBD>"));
|
||||
var data1 = Encoding.UTF8.GetBytes(str1);
|
||||
|
||||
var item1 = new TS_BLB01 { Data = data1 };
|
||||
Assert.Equal(1, g.dameng.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.dameng.Select<TS_BLB01>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(item1.Data.Length, item2.Data.Length);
|
||||
|
||||
var str2 = Encoding.UTF8.GetString(item2.Data);
|
||||
Assert.Equal(str1, str2);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_BLB01 { Data = data1 };
|
||||
Assert.Throws<Exception>(() => g.dameng.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
//DmException: <20>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ض<EFBFBD>
|
||||
}
|
||||
class TS_BLB01
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public byte[] Data { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void StringLength()
|
||||
{
|
||||
@ -238,11 +306,6 @@ namespace FreeSql.Tests.Dameng
|
||||
[Fact]
|
||||
public void CurdAllField()
|
||||
{
|
||||
var item = new TableAllType { };
|
||||
item.Id = (int)insert.AppendData(item).ExecuteIdentity();
|
||||
|
||||
var newitem = select.Where(a => a.Id == item.Id).ToOne();
|
||||
|
||||
var item2 = new TableAllType
|
||||
{
|
||||
Bool = true,
|
||||
|
@ -1497,15 +1497,6 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.tostring, find.tostring);
|
||||
Assert.Equal(false, find.tostring);
|
||||
|
||||
item = new BoolNullableMap { tostring = null };
|
||||
Assert.Equal(1, orm.Insert<BoolNullableMap>().AppendData(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == false).First());
|
||||
find = orm.Select<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.tostring, find.tostring);
|
||||
Assert.Null(find.tostring);
|
||||
|
||||
//update all
|
||||
item.tostring = true;
|
||||
Assert.Equal(1, orm.Update<BoolNullableMap>().SetSource(item).ExecuteAffrows());
|
||||
@ -1523,15 +1514,6 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.tostring, find.tostring);
|
||||
Assert.Equal(false, find.tostring);
|
||||
|
||||
item.tostring = null;
|
||||
Assert.Equal(1, orm.Update<BoolNullableMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == false).First());
|
||||
find = orm.Select<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.tostring, find.tostring);
|
||||
Assert.Null(find.tostring);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<BoolNullableMap>().Where(a => a.id == item.id).Set(a => a.tostring, true).ExecuteAffrows());
|
||||
find = orm.Select<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == true).First();
|
||||
@ -1545,17 +1527,9 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(false, find.tostring);
|
||||
|
||||
Assert.Equal(1, orm.Update<BoolNullableMap>().Where(a => a.id == item.id).Set(a => a.tostring, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == false).First());
|
||||
find = orm.Select<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.tostring);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == true).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == false).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == null).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == false).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<BoolNullableMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
|
||||
|
@ -84,17 +84,9 @@ namespace FreeSql.Tests.DamengMapType
|
||||
{
|
||||
//insert
|
||||
var orm = g.dameng;
|
||||
var item = new EnumTestMap { };
|
||||
var item = new EnumTestMap { enumnullable_to_string = ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD> };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
item = new EnumTestMap { enumnullable_to_string = ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD> };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
@ -109,15 +101,6 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, find.enumnullable_to_string);
|
||||
|
||||
item.enumnullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First();
|
||||
@ -125,19 +108,10 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_string);
|
||||
|
||||
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
Assert.NotNull(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -99,17 +99,9 @@ namespace FreeSql.Tests.DamengMapType
|
||||
{
|
||||
//insert
|
||||
var orm = g.dameng;
|
||||
var item = new ToStringMap { };
|
||||
var item = new ToStringMap { enumnullable_to_string = ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD> };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
item = new ToStringMap { enumnullable_to_string = ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD> };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
@ -124,15 +116,6 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, find.enumnullable_to_string);
|
||||
|
||||
item.enumnullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First();
|
||||
@ -140,19 +123,10 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_string);
|
||||
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
Assert.NotNull(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void BigInteger1()
|
||||
@ -216,17 +190,9 @@ namespace FreeSql.Tests.DamengMapType
|
||||
{
|
||||
//insert
|
||||
var orm = g.dameng;
|
||||
var item = new ToStringMap { };
|
||||
var item = new ToStringMap { bigintegernullable_to_string = 101 };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
Assert.Null(find.bigintegernullable_to_string);
|
||||
|
||||
item = new ToStringMap { bigintegernullable_to_string = 101 };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 101).First();
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 101).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
@ -241,15 +207,6 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
Assert.Equal(2004, find.bigintegernullable_to_string);
|
||||
|
||||
item.bigintegernullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
Assert.Null(find.bigintegernullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.bigintegernullable_to_string, 998).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).First();
|
||||
@ -257,18 +214,9 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(998, find.bigintegernullable_to_string);
|
||||
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.bigintegernullable_to_string, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.bigintegernullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
@ -513,18 +461,10 @@ namespace FreeSql.Tests.DamengMapType
|
||||
{
|
||||
//insert
|
||||
var orm = g.dameng;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
Assert.Null(find.guidnullable_to_string);
|
||||
|
||||
var newid = Guid.NewGuid();
|
||||
item = new ToStringMap { guidnullable_to_string = newid };
|
||||
var item = new ToStringMap { guidnullable_to_string = newid };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == newid).First();
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
@ -540,14 +480,6 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
Assert.Equal(newid, find.guidnullable_to_string);
|
||||
|
||||
item.guidnullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
Assert.Null(find.guidnullable_to_string);
|
||||
|
||||
//update set
|
||||
newid = Guid.NewGuid();
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.guidnullable_to_string, newid).ExecuteAffrows());
|
||||
@ -556,14 +488,8 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(newid, find.guidnullable_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.guidnullable_to_string, null).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.guidnullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,94 @@ namespace FreeSql.Tests.MySql
|
||||
{
|
||||
public class MySqlCodeFirstTest
|
||||
{
|
||||
[Fact]
|
||||
public void Text_StringLength_1()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 1000).Select(a => "<22><><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><D0B9><EFBFBD>"));
|
||||
|
||||
var item1 = new TS_TEXT02 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.mysql.Select<TS_TEXT02>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT02 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT02
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(StringLength = -1)]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Text()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 1000).Select(a => "<22><><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><D0B9><EFBFBD>"));
|
||||
|
||||
var item1 = new TS_TEXT01 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.mysql.Select<TS_TEXT01>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT01 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT01
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(DbType = "text")]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Text_StringLength_2()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "<22><><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><D0B9><EFBFBD>"));
|
||||
|
||||
var item1 = new TS_TEXT04 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.mysql.Select<TS_TEXT04>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT04 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT04
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(StringLength = -2)]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LongText()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "<22><><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><D0B9><EFBFBD>"));
|
||||
|
||||
var item1 = new TS_TEXT03 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.mysql.Select<TS_TEXT03>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT03 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT03
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(DbType = "longtext")]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StringLength()
|
||||
{
|
||||
|
Reference in New Issue
Block a user