mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 04:18:16 +08:00
mysql/sqlserver CodeFirst 完成测试
This commit is contained in:
@ -34,6 +34,83 @@ namespace FreeSql.Tests.MySql {
|
||||
|
||||
[Fact]
|
||||
public void ToList() {
|
||||
var t1 = g.mysql.Select<TestInfo>().Where("").Where(a => a.Id > 0).Skip(100).Limit(200).ToSql();
|
||||
var t2 = g.mysql.Select<TestInfo>().As("b").Where("").Where(a => a.Id > 0).Skip(100).Limit(200).ToSql();
|
||||
|
||||
|
||||
var sql1 = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid).ToSql();
|
||||
var sql2 = select.LeftJoin<TestTypeInfo>((a, b) => a.TestTypeInfoGuid == b.Guid && b.Name == "111").ToSql();
|
||||
var sql3 = select.LeftJoin("TestTypeInfo b on b.Guid = a.TypeGuid").ToSql();
|
||||
|
||||
//g.mysql.Select<TestInfo, TestTypeInfo, TestTypeParentInfo>().Join((a, b, c) => new Model.JoinResult3(
|
||||
// Model.JoinType.LeftJoin, a.TypeGuid == b.Guid,
|
||||
// Model.JoinType.InnerJoin, c.Id == b.ParentId && c.Name == "xxx")
|
||||
//);
|
||||
|
||||
//var sql4 = select.From<TestTypeInfo, TestTypeParentInfo>((a, b, c) => new SelectFrom()
|
||||
// .InnerJoin(a.TypeGuid == b.Guid)
|
||||
// .LeftJoin(c.Id == b.ParentId)
|
||||
// .Where(b.Name == "xxx"))
|
||||
//.Where(a => a.Id == 1).ToSql();
|
||||
|
||||
var sql4 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
|
||||
.InnerJoin(a => a.TestTypeInfoGuid == b.Guid)
|
||||
.LeftJoin(a => c.Id == b.ParentId)
|
||||
.Where(a => b.Name == "xxx")).ToSql();
|
||||
//.Where(a => a.Id == 1).ToSql();
|
||||
|
||||
|
||||
var list111 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
|
||||
.InnerJoin(a => a.TestTypeInfoGuid == b.Guid)
|
||||
.LeftJoin(a => c.Id == b.ParentId)
|
||||
.Where(a => b.Name != "xxx"));
|
||||
var list111sql = list111.ToSql();
|
||||
var list111data = list111.ToList((a, b, c) => new {
|
||||
a.Id,
|
||||
title_substring = a.Title.Substring(0, 1),
|
||||
a.Type,
|
||||
ccc = new { a.Id, a.Title },
|
||||
tp = a.Type,
|
||||
tp2 = new {
|
||||
a.Id,
|
||||
tp2 = a.Type.Name
|
||||
},
|
||||
tp3 = new {
|
||||
a.Id,
|
||||
tp33 = new {
|
||||
a.Id
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var ttt122 = g.mysql.Select<TestTypeParentInfo>().Where(a => a.Id > 0).ToSql();
|
||||
var sql5 = g.mysql.Select<TestInfo>().From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s).Where((a, b, c) => a.Id == b.ParentId).ToSql();
|
||||
var t11112 = g.mysql.Select<TestInfo>().ToList(a => new {
|
||||
a.Id,
|
||||
a.Title,
|
||||
a.Type,
|
||||
ccc = new { a.Id, a.Title },
|
||||
tp = a.Type,
|
||||
tp2 = new {
|
||||
a.Id,
|
||||
tp2 = a.Type.Name
|
||||
},
|
||||
tp3 = new {
|
||||
a.Id,
|
||||
tp33 = new {
|
||||
a.Id
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var t100 = g.mysql.Select<TestInfo>().Where("").Where(a => a.Id > 0).Skip(100).Limit(200).Caching(50).ToList();
|
||||
var t101 = g.mysql.Select<TestInfo>().As("b").Where("").Where(a => a.Id > 0).Skip(100).Limit(200).Caching(50).ToList();
|
||||
|
||||
|
||||
var t1111 = g.mysql.Select<TestInfo>().ToList(a => new { a.Id, a.Title, a.Type });
|
||||
|
||||
var t2222 = g.mysql.Select<TestInfo>().ToList(a => new { a.Id, a.Title, a.Type.Name });
|
||||
}
|
||||
[Fact]
|
||||
public void ToOne() {
|
||||
|
@ -7,6 +7,24 @@ using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.MySql {
|
||||
public class MySqlCodeFirstTest {
|
||||
|
||||
[Fact]
|
||||
public void AddField() {
|
||||
var sql = g.mysql.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
|
||||
|
||||
var id = g.mysql.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteIdentity();
|
||||
}
|
||||
|
||||
public class TopicAddField {
|
||||
[Column(IsIdentity = true)]
|
||||
public int? Id { get; set; }
|
||||
|
||||
public int name { get; set; }
|
||||
|
||||
[Column(DbType = "varchar(200) not null", OldName = "title")]
|
||||
public string title222 { get; set; } = "10";
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetComparisonDDLStatements() {
|
||||
|
||||
|
114
FreeSql.Tests/MySql/MySqlExpression/ConvertTest.cs
Normal file
114
FreeSql.Tests/MySql/MySqlExpression/ConvertTest.cs
Normal file
@ -0,0 +1,114 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.MySqlExpression {
|
||||
public class ConvertTest {
|
||||
|
||||
ISelect<Topic> select => g.mysql.Select<Topic>();
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic {
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
public int Clicks { get; set; }
|
||||
public int TestTypeInfoGuid { get; set; }
|
||||
public TestTypeInfo Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
class TestTypeInfo {
|
||||
public int Guid { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public TestTypeParentInfo Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
class TestTypeParentInfo {
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public List<TestTypeInfo> Types { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToBoolean() {
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => (Convert.ToBoolean(a.Clicks) ? 1 : 2) > 0).ToList());
|
||||
//SELECT a.`Id`, a.`Clicks`, a.`TestTypeInfoGuid`, a.`Title`, a.`CreateTime`
|
||||
//FROM `tb_topic` a
|
||||
//WHERE ((a.`Clicks` not in ('0','false')))
|
||||
}
|
||||
[Fact]
|
||||
public void ToByte() {
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToByte(a.Clicks) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToChar() {
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToBoolean(a.Clicks)).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToDateTime() {
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToDateTime(a.CreateTime.ToString()).Year > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToDecimal() {
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToDecimal(a.Clicks) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToDouble() {
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToDouble(a.Clicks) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToInt16() {
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToInt16(a.Clicks) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToInt32() {
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToInt32(a.Clicks) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToInt64() {
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToInt64(a.Clicks) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToSByte() {
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToSByte(a.Clicks) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToSingle() {
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToSingle(a.Clicks) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void this_ToString() {
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToString(a.Clicks).Equals("")).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToUInt16() {
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToUInt16(a.Clicks) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToUInt32() {
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToUInt32(a.Clicks) > 0).ToList());
|
||||
}
|
||||
[Fact]
|
||||
public void ToUInt64() {
|
||||
var data = new List<object>();
|
||||
data.Add(select.Where(a => Convert.ToUInt64(a.Clicks) > 0).ToList());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user