mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 优化 表达式 true && ... 解析的处理;
- 优化 Navigate 指定联合键关系时,对属性顺序的要求,当类型不一样、名称一样时无须指明属性的顺序,如:[Navigate("MemberId, ShopId")];
This commit is contained in:
parent
619c57c254
commit
3ebc01f88d
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
|
||||
<Version>0.7.5</Version>
|
||||
<Version>0.7.6</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql 扩展包,可实现【延时加载】属性.</Description>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
|
||||
<Version>0.7.5</Version>
|
||||
<Version>0.7.6</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
|
||||
<Version>0.7.5</Version>
|
||||
<Version>0.7.6</Version>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql Implementation of General Repository, Support MySql/SqlServer/PostgreSQL/Oracle/Sqlite, and read/write separation、and split table.</Description>
|
||||
<PackageProjectUrl>https://github.com/2881099/FreeSql/wiki/Repository</PackageProjectUrl>
|
||||
|
@ -21,7 +21,6 @@
|
||||
<Folder Include="DataAnnotations\MySql\" />
|
||||
<Folder Include="DataAnnotations\SqlServer\" />
|
||||
<Folder Include="DataContext\MySql\" />
|
||||
<Folder Include="Other\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
89
FreeSql.Tests/FreeSql.Tests/Other/CustomerCheckupGroup.cs
Normal file
89
FreeSql.Tests/FreeSql.Tests/Other/CustomerCheckupGroup.cs
Normal file
@ -0,0 +1,89 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码由工具生成。
|
||||
// 运行时版本:4.0.30319.42000
|
||||
// Website: http://www.freesql.net
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||
// 重新生成代码,这些更改将会丢失。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using FreeSql.DataAnnotations;
|
||||
|
||||
namespace ZX.Model {
|
||||
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class CustomerCheckupGroup {
|
||||
|
||||
[JsonProperty, Column(IsPrimary = true)]
|
||||
public short ShopId { get => _ShopId; set {
|
||||
if (_ShopId == value) return;
|
||||
_ShopId = value;
|
||||
} }
|
||||
private short _ShopId;
|
||||
|
||||
[JsonProperty, Column(DbType = "varchar(50)", IsPrimary = true)]
|
||||
public string Id { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "nvarchar(50)")]
|
||||
public string MemberId { get => _MemberId; set {
|
||||
if (_MemberId == value) return;
|
||||
_MemberId = value;
|
||||
} }
|
||||
private string _MemberId;
|
||||
|
||||
[JsonProperty, Column(DbType = "varchar(50)")]
|
||||
public string Discount { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "varchar(50)")]
|
||||
public string Doctor { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public DateTime? FirstTime { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "varchar(50)")]
|
||||
public string Group { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public DateTime? InsertTime { get; set; }
|
||||
|
||||
[JsonProperty, Column(Name = "isOK")]
|
||||
public bool? IsOK { get; set; }
|
||||
|
||||
[JsonProperty, Column(Name = "isPay", DbType = "varchar(50)")]
|
||||
public string IsPay { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "varchar(50)")]
|
||||
public string Office { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "varchar(50)")]
|
||||
public string PayType { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "decimal(9,2)")]
|
||||
public decimal? Price { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public DateTime? UpdateTime { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "decimal(9,2)")]
|
||||
public decimal? Value { get; set; }
|
||||
|
||||
|
||||
#region 外键 => 导航属性,ManyToOne/OneToOne
|
||||
|
||||
[Navigate("ShopId, MemberId")]
|
||||
public virtual CustomerMember CustomerMember { get; set; }
|
||||
#endregion
|
||||
|
||||
#region 外键 => 导航属性,ManyToMany
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
108
FreeSql.Tests/FreeSql.Tests/Other/CustomerMember.cs
Normal file
108
FreeSql.Tests/FreeSql.Tests/Other/CustomerMember.cs
Normal file
@ -0,0 +1,108 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码由工具生成。
|
||||
// 运行时版本:4.0.30319.42000
|
||||
// Website: http://www.freesql.net
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||
// 重新生成代码,这些更改将会丢失。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using FreeSql.DataAnnotations;
|
||||
|
||||
namespace ZX.Model {
|
||||
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class CustomerMember {
|
||||
public CustomerMember()
|
||||
{
|
||||
CheckupGroups = new List<CustomerCheckupGroup>();
|
||||
}
|
||||
|
||||
[JsonProperty, Column(DbType = "nvarchar(50)", IsPrimary = true)]
|
||||
public string MemberId { get; set; }
|
||||
|
||||
[JsonProperty, Column(IsPrimary = true)]
|
||||
public short ShopId { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public long? CustomerId { get => _CustomerId; set {
|
||||
if (_CustomerId == value) return;
|
||||
_CustomerId = value;
|
||||
} }
|
||||
private long? _CustomerId;
|
||||
|
||||
[JsonProperty, Column(DbType = "varchar(500)")]
|
||||
public string Address { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "smalldatetime")]
|
||||
public DateTime? Birthday { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "varchar(50)")]
|
||||
public string CardNo { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "varchar(50)")]
|
||||
public string CardType { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "varchar(50)")]
|
||||
public string Doctor { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public DateTime? EndDate { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "varchar(50)")]
|
||||
public string Group { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "varchar(50)")]
|
||||
public string Marry { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "varchar(50)")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "varchar(50)")]
|
||||
public string Part { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "varchar(50)")]
|
||||
public string PayType { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "varchar(50)")]
|
||||
public string Phone { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "varchar(10)")]
|
||||
public string Sex { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public DateTime? StartDate { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "text")]
|
||||
public string Suggest { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "text")]
|
||||
public string SumUp { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "varchar(50)")]
|
||||
public string Team { get; set; }
|
||||
|
||||
[JsonProperty, Column(DbType = "decimal(9,2)")]
|
||||
public decimal? TotalFee { get; set; }
|
||||
|
||||
|
||||
#region 外键 => 导航属性,ManyToOne/OneToOne
|
||||
|
||||
[Navigate("MemberId,ShopId")]
|
||||
public virtual List<CustomerCheckupGroup> CheckupGroups { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region 外键 => 导航属性,ManyToMany
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
@ -296,6 +296,14 @@ namespace FreeSql.Tests
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
var teklksjdg = g.sqlite.Select<ZX.Model.CustomerCheckupGroup>()
|
||||
.Where(a => true && a.CustomerMember.Group == "xxx")
|
||||
.ToSql();
|
||||
|
||||
var sklgjlskdg = g.sqlite.Select<ZX.Model.CustomerMember>()
|
||||
.Where(a => a.CheckupGroups.AsSelect().Any())
|
||||
.ToSql();
|
||||
|
||||
var tkdkdksql = g.sqlite.Select<TaskBuild>().From<Templates, Templates>((a, b, c) =>
|
||||
a.LeftJoin(aa => aa.TemplatesId == b.Id2 && b.Code == "xx")
|
||||
.LeftJoin(aa => aa.TemplatesId == c.Id2))
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
|
||||
<Version>0.7.5</Version>
|
||||
<Version>0.7.6</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>
|
||||
|
@ -327,16 +327,7 @@ namespace FreeSql.Internal
|
||||
if (exp.NodeType == ExpressionType.MemberAccess && isBool && sql.Contains(" IS ") == false && sql.Contains(" = ") == false)
|
||||
return $"{sql} = {formatSql(true, null)}";
|
||||
if (isBool)
|
||||
{
|
||||
switch (sql)
|
||||
{
|
||||
case "1":
|
||||
case "'t'": return "1=1";
|
||||
case "0":
|
||||
case "'f'": return "1=2";
|
||||
default: return sql;
|
||||
}
|
||||
}
|
||||
return GetBoolString(sql);
|
||||
return sql;
|
||||
}
|
||||
|
||||
@ -347,16 +338,7 @@ namespace FreeSql.Internal
|
||||
if (exp.NodeType == ExpressionType.MemberAccess && isBool && sql.Contains(" IS ") == false && sql.Contains(" = ") == false)
|
||||
return $"{sql} = {formatSql(true, null)}";
|
||||
if (isBool)
|
||||
{
|
||||
switch (sql)
|
||||
{
|
||||
case "1":
|
||||
case "'t'": return "1=1";
|
||||
case "0":
|
||||
case "'f'": return "1=2";
|
||||
default: return sql;
|
||||
}
|
||||
}
|
||||
return GetBoolString(sql);
|
||||
return sql;
|
||||
}
|
||||
public void ExpressionJoinLambda(List<SelectTableInfo> _tables, SelectTableInfoType tbtype, Expression exp, Func<Expression[], string> getSelectGroupingMapString)
|
||||
@ -367,16 +349,8 @@ namespace FreeSql.Internal
|
||||
if (exp.NodeType == ExpressionType.MemberAccess && isBool && sql.Contains(" IS ") == false && sql.Contains(" = ") == false)
|
||||
sql = $"{sql} = {formatSql(true, null)}";
|
||||
if (isBool)
|
||||
{
|
||||
switch (sql)
|
||||
{
|
||||
case "1":
|
||||
case "'t'": sql = "1=1"; break;
|
||||
case "0":
|
||||
case "'f'": sql = "1=2"; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
sql = GetBoolString(sql);
|
||||
|
||||
if (_tables.Count > tbidx)
|
||||
{
|
||||
_tables[tbidx].Type = tbtype;
|
||||
@ -403,6 +377,17 @@ namespace FreeSql.Internal
|
||||
static MethodInfo MethodDateTimeSubtractDateTime = typeof(DateTime).GetMethod("Subtract", new Type[] { typeof(DateTime) });
|
||||
static MethodInfo MethodDateTimeSubtractTimeSpan = typeof(DateTime).GetMethod("Subtract", new Type[] { typeof(TimeSpan) });
|
||||
|
||||
static string GetBoolString(string sql)
|
||||
{
|
||||
switch (sql)
|
||||
{
|
||||
case "1":
|
||||
case "'t'": return "1=1";
|
||||
case "0":
|
||||
case "'f'": return "1=2";
|
||||
default: return sql;
|
||||
}
|
||||
}
|
||||
public string ExpressionBinary(string oper, Expression leftExp, Expression rightExp, ExpTSC tsc)
|
||||
{
|
||||
switch (oper)
|
||||
@ -483,7 +468,15 @@ namespace FreeSql.Internal
|
||||
left = tmp;
|
||||
}
|
||||
if (right == "NULL") oper = oper == "=" ? " IS " : " IS NOT ";
|
||||
if (oper == "%") return _common.Mod(left, right, leftExp.Type, rightExp.Type);
|
||||
switch(oper)
|
||||
{
|
||||
case "%": return _common.Mod(left, right, leftExp.Type, rightExp.Type);
|
||||
case "AND":
|
||||
case "OR":
|
||||
left = GetBoolString(left);
|
||||
right = GetBoolString(right);
|
||||
break;
|
||||
}
|
||||
tsc.mapType = null;
|
||||
return $"{left} {oper} {right}";
|
||||
}
|
||||
|
@ -568,6 +568,19 @@ namespace FreeSql.Internal
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
}
|
||||
if (trytb.Primarys.Length > 1)
|
||||
{
|
||||
if (trytb.Primarys.Select(a => a.CsType).Distinct().Count() == trytb.Primarys.Length)
|
||||
{
|
||||
var pkList = trytb.Primarys.ToList();
|
||||
bindColumns.Sort((a, b) => pkList.FindIndex(c => c.CsType == a.CsType).CompareTo(pkList.FindIndex(c => c.CsType == b.CsType)));
|
||||
}
|
||||
else if (string.Compare(string.Join(",", trytb.Primarys.Select(a => a.CsName).OrderBy(a => a)), string.Join(",", bindColumns.Select(a => a.CsName).OrderBy(a => a)), true) == 0)
|
||||
{
|
||||
var pkList = trytb.Primarys.ToList();
|
||||
bindColumns.Sort((a, b) => pkList.FindIndex(c => string.Compare(c.CsName, a.CsName, true) == 0).CompareTo(pkList.FindIndex(c => string.Compare(c.CsName, b.CsName, true) == 0)));
|
||||
}
|
||||
}
|
||||
for (var a = 0; nvref.Exception == null && a < trytb.Primarys.Length; a++)
|
||||
{
|
||||
var findtrytbPkCsName = trytb.Primarys[a].CsName.TrimStart('_');
|
||||
@ -705,6 +718,19 @@ namespace FreeSql.Internal
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
}
|
||||
if (tbref.Primarys.Length > 1)
|
||||
{
|
||||
if (tbref.Primarys.Select(a => a.CsType).Distinct().Count() == tbref.Primarys.Length)
|
||||
{
|
||||
var pkList = tbref.Primarys.ToList();
|
||||
bindColumns.Sort((a, b) => pkList.FindIndex(c => c.CsType == a.CsType).CompareTo(pkList.FindIndex(c => c.CsType == b.CsType)));
|
||||
}
|
||||
else if (string.Compare(string.Join(",", tbref.Primarys.Select(a => a.CsName).OrderBy(a => a)), string.Join(",", bindColumns.Select(a => a.CsName).OrderBy(a => a)), true) == 0)
|
||||
{
|
||||
var pkList = tbref.Primarys.ToList();
|
||||
bindColumns.Sort((a, b) => pkList.FindIndex(c => string.Compare(c.CsName, a.CsName, true) == 0).CompareTo(pkList.FindIndex(c => string.Compare(c.CsName, b.CsName, true) == 0)));
|
||||
}
|
||||
}
|
||||
for (var a = 0; nvref.Exception == null && a < tbref.Primarys.Length; a++)
|
||||
{
|
||||
var findtbrefPkCsName = tbref.Primarys[a].CsName.TrimStart('_');
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
|
||||
<Version>0.7.5</Version>
|
||||
<Version>0.7.6</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql 数据库实现,基于 MySql 5.6</Description>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
|
||||
<Version>0.7.5</Version>
|
||||
<Version>0.7.6</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql 数据库实现,基于 MySql 5.6</Description>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
|
||||
<Version>0.7.5</Version>
|
||||
<Version>0.7.6</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql 数据库实现,基于 Oracle 11</Description>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
|
||||
<Version>0.7.5</Version>
|
||||
<Version>0.7.6</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql 数据库实现,基于 PostgreSQL 9.5</Description>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net451</TargetFrameworks>
|
||||
<Version>0.7.5</Version>
|
||||
<Version>0.7.6</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql 数据库实现,基于 SqlServer 2005+,并根据版本适配分页方法:row_number 或 offset fetch next</Description>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
|
||||
<Version>0.7.5</Version>
|
||||
<Version>0.7.6</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql 数据库实现,基于 Sqlite 3.0</Description>
|
||||
|
Loading…
x
Reference in New Issue
Block a user