From 165abea93c3575d5f8d6b02c9399c3f99d2a63b0 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Fri, 6 Jun 2025 18:43:03 +0800 Subject: [PATCH] Add demo --- .../UserTestCases/UnitTest/Unitdfdaysss.cs | 469 ++++++++++++++++++ 1 file changed, 469 insertions(+) create mode 100644 Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/Unitdfdaysss.cs diff --git a/Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/Unitdfdaysss.cs b/Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/Unitdfdaysss.cs new file mode 100644 index 000000000..63afc822c --- /dev/null +++ b/Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/Unitdfdaysss.cs @@ -0,0 +1,469 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Drawing.Drawing2D; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + public class Unitdfdaysss + { + + public static void Init() + { + var db = NewUnitTest.Db; + + var sql1 = + db.Queryable() + .Select(p => new StoreBrandOther + { + BrandName = string.IsNullOrEmpty( + SqlFunc.Subqueryable().Where(n => n.Id == p.BrandId).Select(n => n.Name) + ) ? "n" : "a" + }).ToSqlString(); + + if (!sql1.Contains(" [OrderJoinItemTemp] [p]")) + { + throw new Exception("unit test"); + } + + var sql2 = + db.Queryable() + .Select(p => new StoreBrandOther + { + BrandName = string.IsNullOrEmpty( + SqlFunc.Subqueryable().Where(n => n.Id == p.BrandId).Select(n => n.Name) + ) + ? "aa" + : SqlFunc + .Subqueryable() + .Where(n => n.Id == p.BrandId) + .Select(n => n.Name), + CategoryName = string.IsNullOrEmpty( + SqlFunc + .Subqueryable() + .Where(n => n.Id == p.ThreeLevelCategory) + .Select(n => n.Name) + ) + ? "为空三级分类" + : SqlFunc + .Subqueryable() + .Where(n => n.Id == p.ThreeLevelCategory) + .Select(n => n.Name), + StoreId = p.StoreId, + OrderItemId = SqlFunc.ToInt64(p.FoodId), + Total = SqlFunc.ToDecimal(p.ItemPrice * p.ItemCount), + CityId = p.CityId, + }) + .ToSqlString(); + + if (!sql2.Contains(" [OrderJoinItemTemp] [p]")) + { + throw new Exception("unit test"); + } + } + } + /// + /// + /// + public partial class Category + { + public Category() + { + + + } + /// + /// Desc: + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:False + /// + public string Name { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:False + /// + public int Level { get; set; } + + /// + /// Desc:父级Id,指向本表 + /// Default: + /// Nullable:True + /// + public int? ParentId { get; set; } + + /// + /// Desc:天猫热卖指数 + /// Default: + /// Nullable:True + /// + public int? TmallIndex { get; set; } + + /// + /// Desc:美团热卖指数 + /// Default: + /// Nullable:True + /// + public int? MtIndex { get; set; } + + /// + /// Desc:饿了么热卖指数 + /// Default: + /// Nullable:True + /// + public int? EleIndex { get; set; } + + /// + /// Desc:京东热卖指数 + /// Default: + /// Nullable:True + /// + public int? JdIndex { get; set; } + + /// + /// Desc: + /// Default:DateTime.Now + /// Nullable:False + /// + public DateTime Created { get; set; } + + /// + /// Desc: + /// Default:DateTime.Now + /// Nullable:False + /// + public DateTime Updated { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public int? CreatorId { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public int? UpdaterId { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public bool? IsDelete { get; set; } + + } + /// + /// + /// + public partial class Brand + { + public Brand() + { + + + } + /// + /// Desc: + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:False + /// + public string Letter { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:False + /// + public string Name { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public string? Desc { get; set; } + + /// + /// Desc: + /// Default:0 + /// Nullable:False + /// + public int Order { get; set; } + + /// + /// Desc: + /// Default:1 + /// Nullable:False + /// + public bool Published { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public string? Website { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public string? Origin { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public string? Company { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:False + /// + public byte[] Version { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public string? Letter2 { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public string? Letter3 { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public long? MTId { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public long? EleId { get; set; } + + /// + /// Desc:废弃 + /// Default: + /// Nullable:True + /// + public int? TmallHotSellIndex { get; set; } + + /// + /// Desc:废弃 + /// Default: + /// Nullable:True + /// + public int? MtHotSellIndex { get; set; } + + /// + /// Desc:废弃 + /// Default: + /// Nullable:True + /// + public int? EleHotSellIndex { get; set; } + + /// + /// Desc:废弃 + /// Default: + /// Nullable:True + /// + public int? JDHotSellIndex { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public int? UpdateUserId { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public DateTime? UpdateTime { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public bool? IsDelete { get; set; } + + /// + /// Desc:logo图片地址 + /// Default: + /// Nullable:True + /// + public string? LogoUrl { get; set; } + + /// + /// Desc:是否重点品牌 + /// Default:0 + /// Nullable:True + /// + public bool? IsTop { get; set; } + + /// + /// Desc:是否自有品牌 + /// Default:0 + /// Nullable:True + /// + public bool? IsPrivate { get; set; } + + } + public class StoreBrandOther + { + /// + /// 店铺ID + /// + public int StoreId { get; set; } + + /// + ///品牌名称 + /// + public string BrandName { get; set; } + + /// + ///三级分类名称 + /// + public string CategoryName { get; set; } + + /// + ///订单明细ID + /// + public long OrderItemId { get; set; } + + /// + ///单价*数量 + /// + public decimal Total { get; set; } + /// + /// 城市ID + /// + public long? CityId { get; set; } + } + /// + /// + /// + public partial class OrderJoinItemTemp + { + public OrderJoinItemTemp() { } + + /// + /// Desc: + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public long? OrderId { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:False + /// + public int Status { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:False + /// + public int StoreId { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:False + /// + [Column(TypeName = "decimal(9,2)")] + public decimal Totals { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public int? FoodId { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public string? FoodName { get; set; } + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public int? BrandId { get; set; } + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public int? ThreeLevelCategory { get; set; } + /// + /// Desc: + /// Default: + /// Nullable:True + /// + public bool? IsFullRefund { get; set; } + [Column(TypeName = "decimal(9,2)")] + public decimal? ItemPrice { get; set; } + public int? ItemCount { get; set; } + public long? CityId { get; set; } + /// + /// Desc: + /// Default: + /// Nullable:False + /// + public DateTime Created { get; set; } + } +}