Browse Source

Exp To SqlBUG

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
2d637ef5c4
  1. 48
      Src/Asp.Net/SqlServerTest/BugTest/Bug1.cs
  2. 139
      Src/Asp.Net/SqlServerTest/Models/Brand.cs
  3. 48
      Src/Asp.Net/SqlServerTest/Models/VendorAndBrand.cs
  4. 2
      Src/Asp.Net/SqlServerTest/SqlServerTest.csproj
  5. 6
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs

48
Src/Asp.Net/SqlServerTest/BugTest/Bug1.cs

@ -1,4 +1,5 @@
using OrmTest.Demo; using Models;
using OrmTest.Demo;
using OrmTest.Models; using OrmTest.Models;
using SqlSugar; using SqlSugar;
using System; using System;
@ -32,22 +33,22 @@ namespace OrmTest.BugTest
var buildId = ""; var buildId = "";
var unitId = ""; var unitId = "";
var keyword = ""; var keyword = "";
GetInstance().CodeFirst.InitTables(typeof(MainTable), typeof(SubTable)); GetInstance().CodeFirst.InitTables(typeof(MainTable), typeof(SubTable), typeof(Brand), typeof(VendorAndBrand));
GetInstance().Queryable<MainTable>().Where(u => GetInstance().Queryable<MainTable>().Where(u =>
(u.CommunityID == communityId || SqlFunc.IsNullOrEmpty(communityId)) && (u.CommunityID == communityId || SqlFunc.IsNullOrEmpty(communityId)) &&
(SqlFunc.Contains(u.BuildID, buildId) || SqlFunc.IsNullOrEmpty(buildId)) && (SqlFunc.Contains(u.BuildID, buildId) || SqlFunc.IsNullOrEmpty(buildId)) &&
(SqlFunc.Contains(u.UnitID, unitId) || SqlFunc.IsNullOrEmpty(unitId)) && (SqlFunc.Contains(u.UnitID, unitId) || SqlFunc.IsNullOrEmpty(unitId)) &&
(SqlFunc.Contains(u.RoomNumber, keyword) || SqlFunc.Contains(u.RoomerName, keyword) || (SqlFunc.Contains(u.RoomNumber, keyword) || SqlFunc.Contains(u.RoomerName, keyword) ||
SqlFunc.Contains(u.HousePlace, keyword) || SqlFunc.Contains(u.UnitName, keyword) || SqlFunc.Contains(u.HousePlace, keyword) || SqlFunc.Contains(u.UnitName, keyword) ||
SqlFunc.Contains(u.BuildName, keyword) || SqlFunc.IsNullOrEmpty(keyword))) SqlFunc.Contains(u.BuildName, keyword) || SqlFunc.IsNullOrEmpty(keyword)))
.GroupBy(ru => new { ru.RoomNumber, ru.RoomID }) .GroupBy(ru => new { ru.RoomNumber, ru.RoomID })
.Select(ru => new .Select(ru => new
{ {
RoomNumber = SqlFunc.AggregateMax(ru.RoomNumber), RoomNumber = SqlFunc.AggregateMax(ru.RoomNumber),
CountRoomer = SqlFunc.AggregateCount(ru.RoomerName), CountRoomer = SqlFunc.AggregateCount(ru.RoomerName),
RoomID = SqlFunc.AggregateMax(ru.RoomID), RoomID = SqlFunc.AggregateMax(ru.RoomID),
Owner = SqlFunc.Subqueryable<SubTable>().Where(r => r.RoomID == ru.RoomID && SqlFunc.Equals(r.RoomUserType, "业主") && SqlFunc.Equals(r.RoomUserType, "业主")).Select(s => s.RoomerName) Owner = SqlFunc.Subqueryable<SubTable>().Where(r => r.RoomID == ru.RoomID && SqlFunc.Equals(r.RoomUserType, "业主") && SqlFunc.Equals(r.RoomUserType, "业主")).Select(s => s.RoomerName)
}).OrderBy((r) => r.RoomNumber, type: OrderByType.Desc).ToPageListAsync(1, 2).Wait(); }).OrderBy((r) => r.RoomNumber, type: OrderByType.Desc).ToPageListAsync(1, 2).Wait();
GetInstance().Updateable<Student>().UpdateColumns(it => GetInstance().Updateable<Student>().UpdateColumns(it =>
new Student() new Student()
@ -62,11 +63,22 @@ SqlFunc.Contains(u.BuildName, keyword) || SqlFunc.IsNullOrEmpty(keyword)))
var list = GetInstance().Queryable<Student, School>((st, sc) => new object[] { var list = GetInstance().Queryable<Student, School>((st, sc) => new object[] {
JoinType.Left,st.SchoolId==sc.Id&&st.CreateTime==DateTime.Now.AddDays(-1) JoinType.Left,st.SchoolId==sc.Id&&st.CreateTime==DateTime.Now.AddDays(-1)
}) })
.Where(st => st.Name == "jack").ToList(); .Where(st => st.Name == "jack").ToList();
GetInstance().Updateable<BugStudent>().Where(it => true).UpdateColumns(it => new BugStudent() { Float = 11 }).ExecuteCommand(); GetInstance().Updateable<BugStudent>().Where(it => true).UpdateColumns(it => new BugStudent() { Float = 11 }).ExecuteCommand();
var reslut= GetInstance().Queryable<BugStudent>().ToList(); var reslut = GetInstance().Queryable<BugStudent>().ToList();
var list2 = GetInstance().Queryable<Brand, VendorAndBrand>((b, vb) => new object[] {
JoinType.Left,b.Id == vb.BrandId
})
.Where((b) => b.BrandType == 1).Select((b) => b).ToList();
var list3 = GetInstance().Queryable<Brand, VendorAndBrand>((b, vb) =>
b.Id == vb.BrandId)
. Where((b) => b.BrandType == 1).Select((b) => b).ToList();
} }

139
Src/Asp.Net/SqlServerTest/Models/Brand.cs

@ -0,0 +1,139 @@
using System;
using System.Linq;
using System.Text;
using SqlSugar;
namespace Models
{
///<summary>
///品牌
///</summary>
[SugarTable("Brand")]
public partial class Brand
{
public Brand(){
}
/// <summary>
/// Desc:
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(IsPrimaryKey=true,IsIdentity=true)]
public int Id {get;set;}
/// <summary>
/// Desc:名称
/// Default:
/// Nullable:False
/// </summary>
public string Name {get;set;}
/// <summary>
/// Desc:品牌别名
/// Default:
/// Nullable:True
/// </summary>
public string AliasName {get;set;}
/// <summary>
/// Desc:顺序
/// Default:0
/// Nullable:True
/// </summary>
public int? Sequence {get;set;}
/// <summary>
/// Desc:网址
/// Default:
/// Nullable:True
/// </summary>
public string Url {get;set;}
/// <summary>
/// Desc:Logo图片路径
/// Default:
/// Nullable:True
/// </summary>
public string LogoPath {get;set;}
/// <summary>
/// Desc:模板类型(0:默认)
/// Default:0
/// Nullable:True
/// </summary>
public int? Templet {get;set;}
/// <summary>
/// Desc:页面标题
/// Default:
/// Nullable:True
/// </summary>
public string PageTitle {get;set;}
/// <summary>
/// Desc:页面关键字
/// Default:
/// Nullable:True
/// </summary>
public string PageKeywords {get;set;}
/// <summary>
/// Desc:PageDesc页面描述
/// Default:
/// Nullable:True
/// </summary>
public string PageDesc {get;set;}
/// <summary>
/// Desc:详细说明
/// Default:
/// Nullable:True
/// </summary>
public string DetailedDesc {get;set;}
/// <summary>
/// Desc:状态(0正常,1暂停,3删除等)
/// Default:0
/// Nullable:True
/// </summary>
public short? Status {get;set;}
/// <summary>
/// Desc:
/// Default:DateTime.Now
/// Nullable:False
/// </summary>
public DateTime CreateTime {get;set;}
/// <summary>
/// Desc:
/// Default:
/// Nullable:True
/// </summary>
public string CreateUser {get;set;}
/// <summary>
/// Desc:ModifyTime
/// Default:DateTime.Now
/// Nullable:True
/// </summary>
public DateTime? ModifyTime {get;set;}
/// <summary>
/// Desc:
/// Default:
/// Nullable:True
/// </summary>
public string ModifyUser {get;set;}
/// <summary>
/// Desc:
/// Default:
/// Nullable:True
/// </summary>
public int? BrandType {get;set;}
}
}

48
Src/Asp.Net/SqlServerTest/Models/VendorAndBrand.cs

@ -0,0 +1,48 @@
using System;
using System.Linq;
using System.Text;
using SqlSugar;
namespace Models
{
///<summary>
///
///</summary>
[SugarTable("VendorAndBrand")]
public partial class VendorAndBrand
{
public VendorAndBrand(){
}
/// <summary>
/// Desc:
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(IsPrimaryKey=true,IsIdentity=true)]
public long Id {get;set;}
/// <summary>
/// Desc:商户编号
/// Default:
/// Nullable:True
/// </summary>
public long? VendorId {get;set;}
/// <summary>
/// Desc:
/// Default:
/// Nullable:True
/// </summary>
public long? BrandId {get;set;}
/// <summary>
/// Desc:创建时间
/// Default:DateTime.Now
/// Nullable:True
/// </summary>
public DateTime? CreateTime {get;set;}
}
}

2
Src/Asp.Net/SqlServerTest/SqlServerTest.csproj

@ -49,7 +49,9 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Models\Brand.cs" />
<Compile Include="BugTest\Bug1.cs" /> <Compile Include="BugTest\Bug1.cs" />
<Compile Include="Models\VendorAndBrand.cs" />
<Compile Include="Demos\F_VersionValidation.cs" /> <Compile Include="Demos\F_VersionValidation.cs" />
<Compile Include="Demos\G_Mapper.cs" /> <Compile Include="Demos\G_Mapper.cs" />
<Compile Include="Demos\H_ExtEntity.cs" /> <Compile Include="Demos\H_ExtEntity.cs" />

6
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs

@ -32,6 +32,10 @@ namespace SqlSugar
{ {
base.Context.Result.Replace(ExpressionConst.FormatSymbol, ExpressionConst.LeftParenthesis + ExpressionConst.FormatSymbol); base.Context.Result.Replace(ExpressionConst.FormatSymbol, ExpressionConst.LeftParenthesis + ExpressionConst.FormatSymbol);
} }
if (leftExpression is UnaryExpression&& (leftExpression as UnaryExpression).Operand is UnaryExpression)
{
leftExpression = (leftExpression as UnaryExpression).Operand;
}
parameter.LeftExpression = leftExpression; parameter.LeftExpression = leftExpression;
parameter.RightExpression = rightExpression; parameter.RightExpression = rightExpression;
base.Expression = leftExpression; base.Expression = leftExpression;
@ -44,7 +48,7 @@ namespace SqlSugar
if (lsbs && parameter.ValueIsNull) if (lsbs && parameter.ValueIsNull)
{ {
base.Context.Result.Replace(ExpressionConst.ExpressionReplace + parameter.Index, isEqual ? "IS" : "IS NOT"); base.Context.Result.Replace(ExpressionConst.ExpressionReplace + parameter.Index, isEqual ? "IS" : "IS NOT");
base.Context.Result.Replace(ExpressionConst.ExpressionReplace + (parameter.Index+1), isEqual ? "IS" : "IS NOT"); base.Context.Result.Replace(ExpressionConst.ExpressionReplace + (parameter.Index + 1), isEqual ? "IS" : "IS NOT");
} }
else else
{ {

Loading…
Cancel
Save