SqlSugar源码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.2 KiB

2 years ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
namespace OrmTest
{
public class UnitSub
{
public static void Init()
{
var db = NewUnitTest.Db;
var sql=db.Queryable<Order>()
.Select(it => new
{
id= SqlFunc.Subqueryable<SubEntity>().Sum(o => o.Id)
}).ToSql();
if (!sql.Key.Contains("id_1"))
{
throw new Exception("unit error");
}
2 years ago
db.CodeFirst.InitTables<SubEntity>();
db.Queryable<Order>()
.Select(it => new
{
id = SqlFunc.Subqueryable<SubEntity>()
.OrderBy(o => o.Id)
.OrderByDesc(o => o.name)
.Select(o=>o.Id)
}).ToList();
db.Queryable<Order>()
.Select(it => new
{
id = SqlFunc.Subqueryable<SubEntity>()
.OrderByDesc(o => o.Id)
.OrderByDesc(o => o.name)
.Select(o => o.Id)
}).ToList();
db.Queryable<Order>()
.Select(it => new
{
id = SqlFunc.Subqueryable<SubEntity>()
.OrderBy(o => o.name)
.OrderBy(o => o.Id)
.Select(o => o.Id)
}).ToList();
db.Queryable<Order>()
.Select(it => new
{
id = SqlFunc.Subqueryable<SubEntity>()
.OrderBy(o => o.Id)
.Select(o => o.Id)
}).ToList();
db.Queryable<Order>()
.Select(it => new
{
id = SqlFunc.Subqueryable<SubEntity>()
.OrderByDesc(o => o.Id)
.Select(o => o.Id)
}).ToList();
db.DbMaintenance.DropTable("UnitSubEntity");
2 years ago
}
2 years ago
[SugarTable("UnitSubEntity")]
2 years ago
public class SubEntity
{
[SqlSugar.SugarColumn(ColumnName ="id_1")]
2 years ago
public decimal Id { get; set; }
public string name { get; set; }
2 years ago
}
}
}