mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
98 lines
2.9 KiB
C#
98 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Drawing;
|
|
using SqlSugar;
|
|
using System.Web;
|
|
namespace OrmTest
|
|
{
|
|
public class UnitTestOneToOne
|
|
{
|
|
public static void Init()
|
|
{
|
|
var db = NewUnitTest.Db;
|
|
db.CurrentConnectionConfig.MoreSettings = new ConnMoreSettings()
|
|
{
|
|
PgSqlIsAutoToLower = false,
|
|
PgSqlIsAutoToLowerCodeFirst = false,
|
|
};
|
|
db.CodeFirst.InitTables<UnitSale, UnitBackSale>();
|
|
db.DbMaintenance.TruncateTable<UnitSale, UnitBackSale>();
|
|
|
|
for (int i = 0; i < 100; i++)
|
|
{
|
|
var sale = new UnitSale
|
|
{
|
|
Name = $"UnitSale{i}",
|
|
IsOn = true,
|
|
};
|
|
int saleId = db.Insertable(sale).ExecuteReturnIdentity();
|
|
|
|
var listBacksale = new List<UnitBackSale> {
|
|
new() {
|
|
Name = $"UnitBackSale{i}",
|
|
IsOn = true,
|
|
SaleId = saleId,
|
|
Money = i + new Random(DateTime.Now.Millisecond).NextDouble()
|
|
},
|
|
new() {
|
|
Name = $"UnitBackSale{i}",
|
|
IsOn = false,
|
|
SaleId = saleId,
|
|
Money = i + new Random(DateTime.Now.Millisecond).NextDouble()
|
|
}
|
|
};
|
|
int result = db.Insertable(listBacksale).ExecuteCommand();
|
|
};
|
|
|
|
var total = db.Queryable<UnitSale>()
|
|
.IncludeLeftJoin(x => x.BackSale)
|
|
.Where(x => x.BackSale.IsOn == true)
|
|
.Sum(x => x.BackSale.Money);
|
|
|
|
var list=db.Reportable(new List<Unitguidsda>() {
|
|
new Unitguidsda()
|
|
}).ToQueryable().ToList();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public class Unitguidsda
|
|
{
|
|
public Guid Id { get; set; } = Guid.NewGuid();
|
|
}
|
|
public static class SqlSugarExtension
|
|
{
|
|
public static List<T> Where<T>(this T thisValue, Func<T, bool> whereExpression) where T : class, new()
|
|
{
|
|
return new List<T>() { thisValue };
|
|
}
|
|
}
|
|
public class UnitSale
|
|
{
|
|
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
|
public int Id { get; set; }
|
|
public string Name { get; set; }
|
|
public bool IsOn { get; set; }
|
|
|
|
|
|
[Navigate(NavigateType.OneToOne, nameof(Id), nameof(UnitBackSale.SaleId))]
|
|
public UnitBackSale BackSale { get; set; }
|
|
}
|
|
|
|
public class UnitBackSale
|
|
{
|
|
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
|
public int Id { get; set; }
|
|
public int SaleId { get; set; }
|
|
public string Name { get; set; }
|
|
public bool IsOn { get; set; }
|
|
public double Money { get; set; }
|
|
}
|
|
}
|
|
|
|
|