mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Add user case test
This commit is contained in:
parent
950461cc4a
commit
7f439ece02
@ -3,7 +3,7 @@ using System;
|
||||
using OrmTest;
|
||||
using SqlSeverTest.UserTestCases.UnitTest;
|
||||
|
||||
namespace SqlSeverTest.UserTestCases
|
||||
namespace OrmTest
|
||||
{
|
||||
public class Cases
|
||||
{
|
||||
@ -13,7 +13,8 @@ namespace SqlSeverTest.UserTestCases
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
public static void Init()
|
||||
{
|
||||
{
|
||||
Unitatadffaa1.Init();
|
||||
UnitOneToManyNsdfafa.Init();
|
||||
UCustomConditionalFunc.Init();
|
||||
//Demo
|
||||
|
@ -7,7 +7,7 @@ using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace SqlSeverTest.UserTestCases.UnitTest
|
||||
namespace OrmTest
|
||||
{
|
||||
internal class UnitOneToManyNsdfafa
|
||||
{
|
||||
|
@ -0,0 +1,98 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
internal class Unitatadffaa1
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
var db = NewUnitTest.Db;
|
||||
|
||||
db.CodeFirst.InitTables<Test001>();
|
||||
db.CodeFirst.InitTables<Test002>();
|
||||
db.DbMaintenance.TruncateTable<Test001,
|
||||
Test002>();
|
||||
|
||||
//用例代码
|
||||
var result = db.Insertable(new Test001() { id = 1, name = "ceshi", age = 11, sex = "33311" }).ExecuteCommand();//用例代码
|
||||
|
||||
var result2 = db.Insertable(new Test002() { id = 1, name = "ceshi2", age = 22, sex = "33322" }).ExecuteCommand();//用例代码
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
|
||||
var data = db.Queryable<Test001>().Where(x => x.id == 1)
|
||||
.Select(x => new
|
||||
{
|
||||
cs = SqlFunc.Subqueryable<Test002>()
|
||||
.ToList(g => new Test003
|
||||
{
|
||||
a = true? "1" : "2"
|
||||
}, true)
|
||||
}).ToList();
|
||||
|
||||
string xx = "1";
|
||||
var data2 = db.Queryable<Test001>().Where(x => x.id == 1)
|
||||
.Select(x => new
|
||||
{
|
||||
cs = SqlFunc.Subqueryable<Test002>()
|
||||
.ToList(g => new Test003
|
||||
{
|
||||
a = xx == "1" ? "1" : "2"
|
||||
}, true)
|
||||
}).ToList();
|
||||
|
||||
// 没问题:
|
||||
|
||||
var data3 = db.Queryable<Test001>().Where(x => x.id == 1)
|
||||
.Where(x => x.id == 1)
|
||||
.Select(x => new
|
||||
{
|
||||
cs = SqlFunc.Subqueryable<Test002>()
|
||||
.LeftJoin<Test001>((g, d) => g.id == d.id)
|
||||
.ToList(g => new Test003
|
||||
{
|
||||
a = g.sex
|
||||
}, true)
|
||||
}).ToList();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Console.WriteLine("异常" + ex.InnerException?.Message);
|
||||
//异常必须声明标量变量 "@constant1"。 报错
|
||||
}
|
||||
}
|
||||
|
||||
[SugarTable("unitTest001aa")]
|
||||
internal class Test001
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
public string sex { get; set; }
|
||||
public int age { get; set; }
|
||||
}
|
||||
[SugarTable("unitTest003aa")]
|
||||
internal class Test003
|
||||
{
|
||||
public string a { get; set; }
|
||||
public string b { get; set; }
|
||||
}
|
||||
internal class Test002
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
public string sex { get; set; }
|
||||
public int age { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user