- 解决 表名名称包含点,无法进行 CRUD 的问题,由于测试的复杂性,此类情况仅支持 MySql/Sqlite CodeFirst 自动迁移;

> 注意:尽量不要使用带点的表名,只有 MySql/Sqlite 对此类表名支持 CodeFirst。但是它不影响 CRUD 功能,使用 [Table(Name = "`sys.config`")] 解决
This commit is contained in:
28810
2020-01-11 02:22:16 +08:00
parent 3fe4c54ee4
commit 994cc475c2
33 changed files with 467 additions and 214 deletions

View File

@ -10,6 +10,33 @@ namespace FreeSql.Tests.MySqlConnector
{
public class MySqlCodeFirstTest
{
[Fact]
public void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>()
{
var item = new tbdot01 { name = "insert" };
g.mysql.Insert(item).ExecuteAffrows();
var find = g.mysql.Select<tbdot01>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal("insert", find.name);
Assert.Equal(1, g.mysql.Update<tbdot01>().Set(a => a.name == "update").Where(a => a.id == item.id).ExecuteAffrows());
find = g.mysql.Select<tbdot01>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal("update", find.name);
Assert.Equal(1, g.mysql.Delete<tbdot01>().Where(a => a.id == item.id).ExecuteAffrows());
find = g.mysql.Select<tbdot01>().Where(a => a.id == item.id).First();
Assert.Null(find);
}
[Table(Name = "`sys.tbdot01`")]
class tbdot01
{
public Guid id { get; set; }
public string name { get; set; }
}
[Fact]
public void <EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>_<EFBFBD>ֶ<EFBFBD>()

View File

@ -10,6 +10,33 @@ namespace FreeSql.Tests.Odbc.MySql
{
public class MySqlCodeFirstTest
{
[Fact]
public void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>()
{
var item = new tbdot01 { name = "insert" };
g.mysql.Insert(item).ExecuteAffrows();
var find = g.mysql.Select<tbdot01>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal("insert", find.name);
Assert.Equal(1, g.mysql.Update<tbdot01>().Set(a => a.name == "update").Where(a => a.id == item.id).ExecuteAffrows());
find = g.mysql.Select<tbdot01>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal("update", find.name);
Assert.Equal(1, g.mysql.Delete<tbdot01>().Where(a => a.id == item.id).ExecuteAffrows());
find = g.mysql.Select<tbdot01>().Where(a => a.id == item.id).First();
Assert.Null(find);
}
[Table(Name = "`sys.tbdot01`")]
class tbdot01
{
public Guid id { get; set; }
public string name { get; set; }
}
[Fact]
public void <EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>_<EFBFBD>ֶ<EFBFBD>()

View File

@ -0,0 +1,78 @@
using FreeSql.DataAnnotations;
using FreeSql;
using System;
using System.Collections.Generic;
using Xunit;
using System.Linq;
using Newtonsoft.Json.Linq;
using NpgsqlTypes;
using Npgsql.LegacyPostgis;
using System.Linq.Expressions;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.Threading;
using System.Data.SqlClient;
using kwlib;
using System.Diagnostics;
using System.IO;
using System.Text;
using FreeSql.Internal;
namespace FreeSql.InternalTests
{
public class CommonUtilsTest
{
[Fact]
public void GetSplitTableNames()
{
var tbname = CommonUtils.GetSplitTableNames("table1", '`', '`', 2);
Assert.Equal("table1", tbname[0]);
tbname = CommonUtils.GetSplitTableNames("table1", '"', '"', 2);
Assert.Equal("table1", tbname[0]);
tbname = CommonUtils.GetSplitTableNames("table1", '[', ']', 2);
Assert.Equal("table1", tbname[0]);
//---
tbname = CommonUtils.GetSplitTableNames("schema1.table1", '`', '`', 2);
Assert.Equal("schema1", tbname[0]);
Assert.Equal("table1", tbname[1]);
tbname = CommonUtils.GetSplitTableNames("schema1.table1", '"', '"', 2);
Assert.Equal("schema1", tbname[0]);
Assert.Equal("table1", tbname[1]);
tbname = CommonUtils.GetSplitTableNames("schema1.table1", '[', ']', 2);
Assert.Equal("schema1", tbname[0]);
Assert.Equal("table1", tbname[1]);
//---
tbname = CommonUtils.GetSplitTableNames("`sys.table1`", '`', '`', 2);
Assert.Equal("sys.table1", tbname[0]);
tbname = CommonUtils.GetSplitTableNames("\"sys.table1\"", '"', '"', 2);
Assert.Equal("sys.table1", tbname[0]);
tbname = CommonUtils.GetSplitTableNames("[sys.table1]", '[', ']', 2);
Assert.Equal("sys.table1", tbname[0]);
//---
tbname = CommonUtils.GetSplitTableNames("`schema1`.`sys.table1`", '`', '`', 2);
Assert.Equal("schema1", tbname[0]);
Assert.Equal("sys.table1", tbname[1]);
tbname = CommonUtils.GetSplitTableNames("\"schema1\".\"sys.table1\"", '"', '"', 2);
Assert.Equal("schema1", tbname[0]);
Assert.Equal("sys.table1", tbname[1]);
tbname = CommonUtils.GetSplitTableNames("[schema1].[sys.table1]", '[', ']', 2);
Assert.Equal("schema1", tbname[0]);
Assert.Equal("sys.table1", tbname[1]);
}
}
}

View File

@ -11,6 +11,34 @@ namespace FreeSql.Tests.MySql
public class MySqlCodeFirstTest
{
[Fact]
public void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>()
{
var item = new tbdot01 { name = "insert" };
g.mysql.Insert(item).ExecuteAffrows();
var find = g.mysql.Select<tbdot01>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal("insert", find.name);
Assert.Equal(1, g.mysql.Update<tbdot01>().Set(a => a.name == "update").Where(a => a.id == item.id).ExecuteAffrows());
find = g.mysql.Select<tbdot01>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal("update", find.name);
Assert.Equal(1, g.mysql.Delete<tbdot01>().Where(a => a.id == item.id).ExecuteAffrows());
find = g.mysql.Select<tbdot01>().Where(a => a.id == item.id).First();
Assert.Null(find);
}
[Table(Name = "`sys.tbdot01`")]
class tbdot01
{
public Guid id { get; set; }
public string name { get; set; }
}
[Fact]
public void <EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>_<EFBFBD>ֶ<EFBFBD>()
{

View File

@ -11,6 +11,34 @@ namespace FreeSql.Tests.Sqlite
public class SqliteCodeFirstTest
{
[Fact]
public void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>()
{
var item = new tbdot01 { name = "insert" };
g.sqlite.Insert(item).ExecuteAffrows();
var find = g.sqlite.Select<tbdot01>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal("insert", find.name);
Assert.Equal(1, g.sqlite.Update<tbdot01>().Set(a => a.name == "update").Where(a => a.id == item.id).ExecuteAffrows());
find = g.sqlite.Select<tbdot01>().Where(a => a.id == item.id).First();
Assert.NotNull(find);
Assert.Equal(item.id, find.id);
Assert.Equal("update", find.name);
Assert.Equal(1, g.sqlite.Delete<tbdot01>().Where(a => a.id == item.id).ExecuteAffrows());
find = g.sqlite.Select<tbdot01>().Where(a => a.id == item.id).First();
Assert.Null(find);
}
[Table(Name = "\"sys.tbdot01\"")]
class tbdot01
{
public Guid id { get; set; }
public string name { get; set; }
}
[Fact]
public void <EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>_<EFBFBD>ֶ<EFBFBD>()
{