mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 增加 ICodeFirst.IsGenerateCommandParameterWithLambda 选项,开启表达式解析的命令参数化;
- 增加 ExpressionCallContext 自定义函数上下文档 DbParameter 属性; - 修复 IncludeMany(a => a.x1.x2.Childs) 当 x1, x2 为 null 的报 null 错误;
This commit is contained in:
parent
12be7f0051
commit
e9a8ad70a1
@ -725,15 +725,15 @@ namespace FreeSql.Tests.Odbc.Default
|
||||
[Fact]
|
||||
public void Sum()
|
||||
{
|
||||
var subquery = select.ToSql(a => new
|
||||
var subquery = select.Where(a => a.Id < 200).ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Sum(b => b.Id)
|
||||
count = select.Where(b => b.Id < 200).Sum(b => b.Id)
|
||||
});
|
||||
var subqueryList = select.ToList(a => new
|
||||
var subqueryList = select.Where(a => a.Id < 200).ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Sum(b => b.Id)
|
||||
count = select.Where(b => b.Id < 200).Sum(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -767,15 +767,15 @@ namespace FreeSql.Tests.Odbc.Default
|
||||
[Fact]
|
||||
public void Avg()
|
||||
{
|
||||
var subquery = select.ToSql(a => new
|
||||
var subquery = select.Where(a => a.Id < 200).ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.Where(b => b.Id < 200).Sum(b => b.Id)
|
||||
});
|
||||
var subqueryList = select.ToList(a => new
|
||||
var subqueryList = select.Where(a => a.Id < 200).ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.Where(b => b.Id < 200).Sum(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
|
@ -1567,30 +1567,5 @@ namespace FreeSql.Tests.Odbc.DefaultMapType
|
||||
public void GuidNullable()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MygisPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisPolygon()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPolygon()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1100,30 +1100,5 @@ namespace FreeSql.Tests.Odbc.DefaultMapType
|
||||
public void GuidNullable()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MygisPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisPolygon()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPolygon()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1567,30 +1567,5 @@ namespace FreeSql.Tests.Odbc.OracleMapType
|
||||
public void GuidNullable()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MygisPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisPolygon()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPolygon()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1101,30 +1101,5 @@ namespace FreeSql.Tests.Odbc.OracleMapType
|
||||
public void GuidNullable()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MygisPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisPolygon()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPolygon()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1567,30 +1567,5 @@ namespace FreeSql.Tests.Odbc.PostgreSQLMapType
|
||||
public void GuidNullable()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MygisPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisPolygon()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPolygon()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1101,30 +1101,5 @@ namespace FreeSql.Tests.Odbc.PostgreSQLMapType
|
||||
public void GuidNullable()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MygisPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisPolygon()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPolygon()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -706,15 +706,15 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
[Fact]
|
||||
public void Sum()
|
||||
{
|
||||
var subquery = select.ToSql(a => new
|
||||
var subquery = select.Where(a => a.Id < 200).ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Sum(b => b.Id)
|
||||
count = select.Where(b => b.Id < 200).Sum(b => b.Id)
|
||||
});
|
||||
var subqueryList = select.ToList(a => new
|
||||
var subqueryList = select.Where(a => a.Id < 200).ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Sum(b => b.Id)
|
||||
count = select.Where(b => b.Id < 200).Sum(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
@ -748,15 +748,15 @@ namespace FreeSql.Tests.Odbc.SqlServer
|
||||
[Fact]
|
||||
public void Avg()
|
||||
{
|
||||
var subquery = select.ToSql(a => new
|
||||
var subquery = select.Where(a => a.Id < 100).ToSql(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.Where(b => b.Id < 100).Avg(b => b.Id)
|
||||
});
|
||||
var subqueryList = select.ToList(a => new
|
||||
var subqueryList = select.Where(a => a.Id < 100).ToList(a => new
|
||||
{
|
||||
all = a,
|
||||
count = select.Avg(b => b.Id)
|
||||
count = select.Where(b => b.Id < 100).Avg(b => b.Id)
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
|
@ -1568,30 +1568,5 @@ namespace FreeSql.Tests.Odbc.SqlServerMapType
|
||||
public void GuidNullable()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MygisPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisPolygon()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPolygon()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1101,30 +1101,5 @@ namespace FreeSql.Tests.Odbc.SqlServerMapType
|
||||
public void GuidNullable()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MygisPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisPolygon()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPolygon()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -204,6 +204,14 @@
|
||||
回复的文本内容
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.Tests.DbFunc.SetDbParameter(System.String,System.Int32)">
|
||||
<summary>
|
||||
设置表达式中的 string 参数化长度,优化执行计划
|
||||
</summary>
|
||||
<param name="that"></param>
|
||||
<param name="size"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:SaleIDO.Entity.Storeage.AdjustPriceOrder">
|
||||
<summary>
|
||||
调价单
|
||||
|
@ -1567,30 +1567,5 @@ namespace FreeSql.Tests.OracleMapType
|
||||
public void GuidNullable()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MygisPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisPolygon()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPolygon()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1101,30 +1101,5 @@ namespace FreeSql.Tests.OracleMapType
|
||||
public void GuidNullable()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MygisPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisPolygon()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPolygon()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1567,30 +1567,5 @@ namespace FreeSql.Tests.PostgreSQLMapType
|
||||
public void GuidNullable()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MygisPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisPolygon()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPolygon()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1101,30 +1101,5 @@ namespace FreeSql.Tests.PostgreSQLMapType
|
||||
public void GuidNullable()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MygisPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisPolygon()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPolygon()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1577,30 +1577,5 @@ namespace FreeSql.Tests.SqlServerMapType
|
||||
public void GuidNullable()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MygisPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisPolygon()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPolygon()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1110,30 +1110,5 @@ namespace FreeSql.Tests.SqlServerMapType
|
||||
public void GuidNullable()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MygisPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisPolygon()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPolygon()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1567,30 +1567,5 @@ namespace FreeSql.Tests.SqliteMapType
|
||||
public void GuidNullable()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MygisPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisPolygon()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPolygon()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1101,30 +1101,5 @@ namespace FreeSql.Tests.SqliteMapType
|
||||
public void GuidNullable()
|
||||
{
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MygisPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisPolygon()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPoint()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiLineString()
|
||||
{
|
||||
}
|
||||
[Fact]
|
||||
public void MygisMultiPolygon()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -185,8 +185,6 @@ namespace FreeSql.Tests
|
||||
[Fact]
|
||||
public void Test02()
|
||||
{
|
||||
var testparmSelect = g.sqlserver.Select<TestMySqlStringIsNullable>().Where(a => a.nvarchar == "11" && a.nvarchar_notnull == "22" && a.nvarchar_null == "33" && a.varchar == "11" && a.varchar_notnull == "22" && a.varchar_null == "33");
|
||||
|
||||
var slsksd = g.mysql.Update<UserLike>().SetSource(new UserLike { Id = Guid.NewGuid(), CreateUserId = 1000, SubjectId = Guid.NewGuid() })
|
||||
.UpdateColumns(a => new
|
||||
{
|
||||
@ -291,6 +289,57 @@ namespace FreeSql.Tests
|
||||
|
||||
var sql = g.sqlite.Select<SysModule>()
|
||||
.ToSql(a => a.CreateTime.FormatDateTime("yyyy-MM-dd"));
|
||||
|
||||
|
||||
var parm1 = "11";
|
||||
var parm2 = "22";
|
||||
var parm3 = "33";
|
||||
var testparmSelect = g.sqlserver.Select<TestMySqlStringIsNullable>()
|
||||
.Where(a =>
|
||||
a.nvarchar == "11" &&
|
||||
a.nvarchar_notnull == "22" &&
|
||||
a.nvarchar_null == "33" &&
|
||||
a.varchar == "11" &&
|
||||
a.varchar_notnull == "22" &&
|
||||
a.varchar_null == "33" &&
|
||||
|
||||
a.nvarchar == parm1 &&
|
||||
a.nvarchar_notnull == parm2 &&
|
||||
a.nvarchar_null == parm3 &&
|
||||
a.varchar == parm3 &&
|
||||
a.varchar_notnull == parm2 &&
|
||||
a.varchar_null == parm3 &&
|
||||
|
||||
a.nvarchar == parm1.SetDbParameter(10) &&
|
||||
a.nvarchar_notnull == parm2.SetDbParameter(11) &&
|
||||
a.nvarchar_null == parm3.SetDbParameter(12) &&
|
||||
a.varchar == parm3.SetDbParameter(13) &&
|
||||
a.varchar_notnull == parm2.SetDbParameter(14) &&
|
||||
a.varchar_null == parm3.SetDbParameter(15) &&
|
||||
|
||||
|
||||
"11" == a.nvarchar &&
|
||||
"22" == a.nvarchar_notnull &&
|
||||
"33" == a.nvarchar_null &&
|
||||
"11" == a.varchar &&
|
||||
"22" == a.varchar_notnull &&
|
||||
"33" == a.varchar_null &&
|
||||
|
||||
parm1 == a.nvarchar &&
|
||||
parm2 == a.nvarchar_notnull &&
|
||||
parm3 == a.nvarchar_null &&
|
||||
parm1 == a.varchar &&
|
||||
parm2 == a.varchar_notnull &&
|
||||
parm3 == a.varchar_null &&
|
||||
|
||||
parm1.SetDbParameter(10) == a.nvarchar &&
|
||||
parm2.SetDbParameter(11) == a.nvarchar_notnull &&
|
||||
parm3.SetDbParameter(12) == a.nvarchar_null &&
|
||||
parm1.SetDbParameter(13) == a.varchar &&
|
||||
parm2.SetDbParameter(14) == a.varchar_notnull &&
|
||||
parm3.SetDbParameter(15) == a.varchar_null
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,7 +350,20 @@ namespace FreeSql.Tests
|
||||
|
||||
public static string FormatDateTime(this DateTime that, string arg1)
|
||||
{
|
||||
return $"date_format({context.Value.Values["arg1"]})";
|
||||
return $"date_format({context.Value.Values["that"]}, {context.Value.Values["arg1"]})";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置表达式中的 string 参数化长度,优化执行计划
|
||||
/// </summary>
|
||||
/// <param name="that"></param>
|
||||
/// <param name="size"></param>
|
||||
/// <returns></returns>
|
||||
public static string SetDbParameter(this string that, int size)
|
||||
{
|
||||
if (context.Value.DbParameter != null)
|
||||
context.Value.DbParameter.Size = size;
|
||||
return context.Value.Values["that"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
|
||||
namespace FreeSql.DataAnnotations
|
||||
@ -18,11 +19,16 @@ namespace FreeSql.DataAnnotations
|
||||
/// <summary>
|
||||
/// 数据库类型,可用于适配多种数据库环境
|
||||
/// </summary>
|
||||
public DataType DataType { get; set; }
|
||||
public DataType DataType { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// 已解析的表达式中参数内容
|
||||
/// </summary>
|
||||
public Dictionary<string, string> Values { get; } = new Dictionary<string, string>();
|
||||
|
||||
/// <summary>
|
||||
/// 主对象的参数化对象,可重塑其属性
|
||||
/// </summary>
|
||||
public DbParameter DbParameter { get; internal set; }
|
||||
}
|
||||
}
|
||||
|
@ -128,16 +128,9 @@ public static partial class FreeSqlGlobalExtensions
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
/// <param name="that"></param>
|
||||
/// <returns></returns>
|
||||
public static ISelect<TEntity> AsSelect<TEntity>(this IEnumerable<TEntity> that) where TEntity : class
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public static ISelect<TEntity> AsSelect<TEntity>(this IEnumerable<TEntity> that, IFreeSql orm = null) where TEntity : class
|
||||
{
|
||||
return orm?.Select<TEntity>();
|
||||
}
|
||||
|
||||
public static FreeSql.ISelect<T> Queryable<T>(this IFreeSql freesql) where T : class => freesql.Select<T>();
|
||||
public static ISelect<TEntity> AsSelect<TEntity>(this IEnumerable<TEntity> that) where TEntity : class => throw new NotImplementedException();
|
||||
public static ISelect<TEntity> AsSelect<TEntity>(this IEnumerable<TEntity> that, IFreeSql orm = null) where TEntity : class => orm?.Select<TEntity>();
|
||||
public static ISelect<T> Queryable<T>(this IFreeSql freesql) where T : class => freesql.Select<T>();
|
||||
|
||||
#region 多表查询
|
||||
/// <summary>
|
||||
|
@ -168,6 +168,11 @@
|
||||
已解析的表达式中参数内容
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.DataAnnotations.ExpressionCallContext.DbParameter">
|
||||
<summary>
|
||||
主对象的参数化对象,可重塑其属性
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.DataAnnotations.IndexAttribute.Name">
|
||||
<summary>
|
||||
索引名
|
||||
@ -587,6 +592,13 @@
|
||||
<param name="value"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.FreeSqlBuilder.UseGenerateCommandParameterWithLambda(System.Boolean)">
|
||||
<summary>
|
||||
是否生成命令参数化执行,针对 lambda 表达式解析
|
||||
</summary>
|
||||
<param name="value"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.FreeSqlBuilder.UseLazyLoading(System.Boolean)">
|
||||
<summary>
|
||||
延时加载导航属性对象,导航属性需要声明 virtual
|
||||
@ -2282,156 +2294,7 @@
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.CurdAfterEventArgs.ElapsedMilliseconds">
|
||||
<summary>
|
||||
耗时(单位:毫秒)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.SyncStructureBeforeEventArgs.Identifier">
|
||||
<summary>
|
||||
标识符,可将 SyncStructureBeforeEventArgs 与 SyncStructureAfterEventArgs 进行匹配
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.SyncStructureBeforeEventArgs.EntityTypes">
|
||||
<summary>
|
||||
实体类型
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.SyncStructureAfterEventArgs.Sql">
|
||||
<summary>
|
||||
执行的 SQL
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.SyncStructureAfterEventArgs.Exception">
|
||||
<summary>
|
||||
发生的错误
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.SyncStructureAfterEventArgs.ElapsedTicks">
|
||||
<summary>
|
||||
耗时(单位:Ticks)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.SyncStructureAfterEventArgs.ElapsedMilliseconds">
|
||||
<summary>
|
||||
耗时(单位:毫秒)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.AuditValueEventArgs.AuditValueType">
|
||||
<summary>
|
||||
类型
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.AuditValueEventArgs.Column">
|
||||
<summary>
|
||||
属性列的元数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.AuditValueEventArgs.Property">
|
||||
<summary>
|
||||
反射的属性信息
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.AuditValueEventArgs.Value">
|
||||
<summary>
|
||||
获取实体的属性值,也可以设置实体的属性新值
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.ICodeFirst.IsAutoSyncStructure">
|
||||
<summary>
|
||||
【开发环境必备】自动同步实体结构到数据库,程序运行中检查实体表是否存在,然后创建或修改
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.ICodeFirst.IsSyncStructureToLower">
|
||||
<summary>
|
||||
转小写同步结构
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.ICodeFirst.IsSyncStructureToUpper">
|
||||
<summary>
|
||||
转大写同步结构
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.ICodeFirst.IsConfigEntityFromDbFirst">
|
||||
<summary>
|
||||
将数据库的主键、自增、索引设置导入,适用 DbFirst 模式,无须在实体类型上设置 [Column(IsPrimary)] 或者 ConfigEntity。此功能目前可用于 mysql/sqlserver/postgresql/oracle。<para></para>
|
||||
本功能会影响 IFreeSql 首次访问的速度。<para></para>
|
||||
若使用 CodeFirst 创建索引后,又直接在数据库上建了索引,若无本功能下一次 CodeFirst 迁移时数据库上创建的索引将被删除
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.ICodeFirst.IsNoneCommandParameter">
|
||||
<summary>
|
||||
不使用命令参数化执行,针对 Insert/Update
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.ICodeFirst.IsLazyLoading">
|
||||
<summary>
|
||||
延时加载导航属性对象,导航属性需要声明 virtual
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.ICodeFirst.GetComparisonDDLStatements``1">
|
||||
<summary>
|
||||
将实体类型与数据库对比,返回DDL语句
|
||||
</summary>
|
||||
<typeparam name="TEntity"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.ICodeFirst.GetComparisonDDLStatements(System.Type[])">
|
||||
<summary>
|
||||
将实体类型集合与数据库对比,返回DDL语句
|
||||
</summary>
|
||||
<param name="entityTypes">实体类型</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.ICodeFirst.GetComparisonDDLStatements(System.Type,System.String)">
|
||||
<summary>
|
||||
将实体类型与数据库对比,返回DDL语句(指定表名)
|
||||
</summary>
|
||||
<param name="entityType">实体类型</param>
|
||||
<param name="tableName">指定表名对比</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.ICodeFirst.SyncStructure``1">
|
||||
<summary>
|
||||
同步实体类型到数据库
|
||||
</summary>
|
||||
<typeparam name="TEntity"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.ICodeFirst.SyncStructure(System.Type[])">
|
||||
<summary>
|
||||
同步实体类型集合到数据库
|
||||
</summary>
|
||||
<param name="entityTypes"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.ICodeFirst.SyncStructure(System.Type,System.String)">
|
||||
<summary>
|
||||
同步实体类型到数据库(指定表名)
|
||||
</summary>
|
||||
<param name="entityType">实体类型</param>
|
||||
<param name="tableName">指定表名对比</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.ICodeFirst.GetDbInfo(System.Type)">
|
||||
<summary>
|
||||
根据 System.Type 获取数据库信息
|
||||
</summary>
|
||||
<param name="type"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.ICodeFirst.ConfigEntity``1(System.Action{FreeSql.DataAnnotations.TableFluent{``0}})">
|
||||
<summary>
|
||||
在外部配置实体的特性
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<param name="entity"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.ICodeFirst.ConfigEntity(System.Type,System.Action{FreeSql.DataAnnotations.TableFluent})">
|
||||
<summary>
|
||||
在外部配置实体的特性
|
||||
</summary>
|
||||
<param name="type"></param>
|
||||
<param name="entity"></param>
|
||||
耗时(单位:毫秒
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.ICodeFirst.GetConfigEntity(System.Type)">
|
||||
@ -2626,6 +2489,165 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSqlGlobalExtensions.Select``3(IFreeSql)">
|
||||
<summary>
|
||||
多表查询
|
||||
</summary>
|
||||
</summary>
|
||||
<param name="column"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IDbFirst.GetCsTypeValue(FreeSql.DatabaseModel.DbColumnInfo)">
|
||||
<summary>
|
||||
获取c#值
|
||||
</summary>
|
||||
<param name="column"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IDbFirst.GetCsType(FreeSql.DatabaseModel.DbColumnInfo)">
|
||||
<summary>
|
||||
获取c#类型,int、long
|
||||
</summary>
|
||||
<param name="column"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IDbFirst.GetCsTypeInfo(FreeSql.DatabaseModel.DbColumnInfo)">
|
||||
<summary>
|
||||
获取c#类型对象
|
||||
</summary>
|
||||
<param name="column"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IDbFirst.GetDataReaderMethod(FreeSql.DatabaseModel.DbColumnInfo)">
|
||||
<summary>
|
||||
获取ado.net读取方法, GetBoolean、GetInt64
|
||||
</summary>
|
||||
<param name="column"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IDbFirst.GetCsStringify(FreeSql.DatabaseModel.DbColumnInfo)">
|
||||
<summary>
|
||||
序列化
|
||||
</summary>
|
||||
<param name="column"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IDbFirst.GetCsParse(FreeSql.DatabaseModel.DbColumnInfo)">
|
||||
<summary>
|
||||
反序列化
|
||||
</summary>
|
||||
<param name="column"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IDbFirst.GetEnumsByDatabase(System.String[])">
|
||||
<summary>
|
||||
获取数据库枚举类型,适用 PostgreSQL
|
||||
</summary>
|
||||
<param name="database"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Internal.CommonProvider.InsertProvider`1.IgnoreCanInsert">
|
||||
<summary>
|
||||
AsType, Ctor, ClearData 三处地方需要重新加载
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.Internal.CommonProvider.UpdateProvider`1.IgnoreCanUpdate">
|
||||
<summary>
|
||||
AsType, Ctor, ClearData 三处地方需要重新加载
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.Internal.CommonUtils.GetProperyCommentBySummary(System.Type)">
|
||||
<summary>
|
||||
通过属性的注释文本,通过 xml 读取
|
||||
</summary>
|
||||
<param name="type"></param>
|
||||
<returns>Dict:key=属性名,value=注释</returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Internal.GlobalFilter.Apply``1(System.String,System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}})">
|
||||
<summary>
|
||||
创建一个过滤器
|
||||
</summary>
|
||||
<typeparam name="TEntity"></typeparam>
|
||||
<param name="name">名字</param>
|
||||
<param name="where">表达式</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:FreeSql.Internal.Model.TableRef.RefMiddleEntityType">
|
||||
<summary>
|
||||
中间表,多对多
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:FreeSql.Internal.StringConvertType.None">
|
||||
<summary>
|
||||
不进行任何处理
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:FreeSql.Internal.StringConvertType.PascalCaseToUnderscore">
|
||||
<summary>
|
||||
将帕斯卡命名字符串转换为下划线分隔字符串
|
||||
<para></para>
|
||||
BigApple -> Big_Apple
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:FreeSql.Internal.StringConvertType.PascalCaseToUnderscoreWithUpper">
|
||||
<summary>
|
||||
将帕斯卡命名字符串转换为下划线分隔字符串,且转换为全大写
|
||||
<para></para>
|
||||
BigApple -> BIG_APPLE
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:FreeSql.Internal.StringConvertType.PascalCaseToUnderscoreWithLower">
|
||||
<summary>
|
||||
将帕斯卡命名字符串转换为下划线分隔字符串,且转换为全小写
|
||||
<para></para>
|
||||
BigApple -> big_apple
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:FreeSql.Internal.StringConvertType.Upper">
|
||||
<summary>
|
||||
将字符串转换为大写
|
||||
<para></para>
|
||||
BigApple -> BIGAPPLE
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:FreeSql.Internal.StringConvertType.Lower">
|
||||
<summary>
|
||||
将字符串转换为小写
|
||||
<para></para>
|
||||
BigApple -> bigapple
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.Internal.StringUtils.PascalCaseToUnderScore(System.String)">
|
||||
<summary>
|
||||
将帕斯卡命名字符串转换为下划线分隔字符串
|
||||
<para></para>
|
||||
BigApple -> Big_Apple
|
||||
</summary>
|
||||
<param name="str"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSqlGlobalExtensions.Distance(System.Drawing.Point,System.Drawing.Point)">
|
||||
<summary>
|
||||
测量两个经纬度的距离,返回单位:米
|
||||
</summary>
|
||||
<param name="that">经纬坐标1</param>
|
||||
<param name="point">经纬坐标2</param>
|
||||
<returns>返回距离(单位:米)</returns>
|
||||
</member>
|
||||
<member name="M:FreeSqlGlobalExtensions.AsSelect``1(System.Collections.Generic.IEnumerable{``0})">
|
||||
<summary>
|
||||
将 IEnumable<T> 转成 ISelect<T>,以便使用 FreeSql 的查询功能。此方法用于 Lambad 表达式中,快速进行集合导航的查询。
|
||||
</summary>
|
||||
<typeparam name="TEntity"></typeparam>
|
||||
<param name="that"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSqlGlobalExtensions.Select``2(IFreeSql)">
|
||||
<summary>
|
||||
多表查询
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSqlGlobalExtensions.Select``3(IFreeSql)">
|
||||
<summary>
|
||||
多表查询
|
||||
|
@ -17,6 +17,7 @@ namespace FreeSql
|
||||
bool _isSyncStructureToUpper = false;
|
||||
bool _isConfigEntityFromDbFirst = false;
|
||||
bool _isNoneCommandParameter = false;
|
||||
bool _isGenerateCommandParameterWithLambda = false;
|
||||
bool _isLazyLoading = false;
|
||||
StringConvertType _entityPropertyConvertType = StringConvertType.None;
|
||||
Action<DbCommand> _aopCommandExecuting = null;
|
||||
@ -100,6 +101,16 @@ namespace FreeSql
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否生成命令参数化执行,针对 lambda 表达式解析
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public FreeSqlBuilder UseGenerateCommandParameterWithLambda(bool value)
|
||||
{
|
||||
_isGenerateCommandParameterWithLambda = value;
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// 延时加载导航属性对象,导航属性需要声明 virtual
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
|
@ -31,6 +31,10 @@ namespace FreeSql
|
||||
/// </summary>
|
||||
bool IsNoneCommandParameter { get; set; }
|
||||
/// <summary>
|
||||
/// 是否生成命令参数化执行,针对 lambda 表达式解析
|
||||
/// </summary>
|
||||
bool IsGenerateCommandParameterWithLambda { get; set; }
|
||||
/// <summary>
|
||||
/// 延时加载导航属性对象,导航属性需要声明 virtual
|
||||
/// </summary>
|
||||
bool IsLazyLoading { get; set; }
|
||||
|
@ -423,13 +423,14 @@ namespace FreeSql.Internal
|
||||
return $"({ExpressionLambdaToSql(leftExp, tsc)} {oper} {ExpressionLambdaToSql(rightExp, tsc)})";
|
||||
}
|
||||
|
||||
Type oldMapType = null;
|
||||
var left = ExpressionLambdaToSql(leftExp, tsc);
|
||||
var leftMapColumn = SearchColumnByField(tsc._tables, tsc.currentTable, left);
|
||||
var isLeftMapType = leftMapColumn != null && new[] { "AND", "OR" }.Contains(oper) == false && (leftMapColumn.Attribute.MapType != rightExp.Type || leftMapColumn.CsType != rightExp.Type);
|
||||
ColumnInfo rightMapColumn = null;
|
||||
var isRightMapType = false;
|
||||
if (isLeftMapType) tsc.mapType = leftMapColumn.Attribute.MapType;
|
||||
|
||||
if (isLeftMapType) oldMapType = tsc.SetMapTypeReturnOld(leftMapColumn.Attribute.MapType);
|
||||
|
||||
var right = ExpressionLambdaToSql(rightExp, tsc);
|
||||
if (right != "NULL" && isLeftMapType)
|
||||
{
|
||||
@ -443,7 +444,7 @@ namespace FreeSql.Internal
|
||||
isRightMapType = rightMapColumn != null && new[] { "AND", "OR" }.Contains(oper) == false && (rightMapColumn.Attribute.MapType != leftExp.Type || rightMapColumn.CsType != leftExp.Type);
|
||||
if (isRightMapType)
|
||||
{
|
||||
tsc.mapType = rightMapColumn.Attribute.MapType;
|
||||
oldMapType = tsc.SetMapTypeReturnOld(rightMapColumn.Attribute.MapType);
|
||||
left = ExpressionLambdaToSql(leftExp, tsc);
|
||||
if (left != "NULL" && isRightMapType)
|
||||
{
|
||||
@ -495,7 +496,7 @@ namespace FreeSql.Internal
|
||||
else right = GetBoolString(right);
|
||||
break;
|
||||
}
|
||||
tsc.mapType = null;
|
||||
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
|
||||
return $"{left} {oper} {right}";
|
||||
}
|
||||
static ConcurrentDictionary<Type, bool> _dicTypeExistsExpressionCallAttribute = new ConcurrentDictionary<Type, bool>();
|
||||
@ -532,7 +533,7 @@ namespace FreeSql.Internal
|
||||
return ExpressionLambdaToSql((exp as UnaryExpression)?.Operand, tsc);
|
||||
case ExpressionType.Negate:
|
||||
case ExpressionType.NegateChecked: return "-" + ExpressionLambdaToSql((exp as UnaryExpression)?.Operand, tsc);
|
||||
case ExpressionType.Constant: return formatSql((exp as ConstantExpression)?.Value, tsc.mapType, tsc.mapColumnTmp, tsc.dbParams);
|
||||
case ExpressionType.Constant: return formatSql((exp as ConstantExpression)?.Value, tsc.mapType, tsc.mapColumnTmp, null);
|
||||
case ExpressionType.Conditional:
|
||||
var condExp = exp as ConditionalExpression;
|
||||
return $"case when {ExpressionLambdaToSql(condExp.Test, tsc)} then {ExpressionLambdaToSql(condExp.IfTrue, tsc)} else {ExpressionLambdaToSql(condExp.IfFalse, tsc)} end";
|
||||
@ -543,15 +544,21 @@ namespace FreeSql.Internal
|
||||
{
|
||||
var ecc = new ExpressionCallContext { DataType = _ado.DataType };
|
||||
var exp3MethodParams = exp3.Method.GetParameters();
|
||||
for (var a = 0; a < exp3.Arguments.Count; a++)
|
||||
var dbParamsIndex = tsc.dbParams?.Count;
|
||||
ecc.Values.Add(exp3MethodParams[0].Name, ExpressionLambdaToSql(exp3.Arguments[0], tsc));
|
||||
if (tsc.dbParams?.Count > dbParamsIndex) ecc.DbParameter = tsc.dbParams.Last();
|
||||
List<DbParameter> oldDbParams = tsc.dbParams;
|
||||
tsc.dbParams = null;
|
||||
for (var a = 1; a < exp3.Arguments.Count; a++)
|
||||
if (exp3.Arguments[a].Type != typeof(ExpressionCallContext))
|
||||
ecc.Values.Add(exp3MethodParams[a].Name, ExpressionLambdaToSql(exp3.Arguments[a], tsc));
|
||||
tsc.dbParams = oldDbParams;
|
||||
|
||||
var exp3InvokeParams = new object[exp3.Arguments.Count];
|
||||
for (var a = 0; a < exp3.Arguments.Count; a++)
|
||||
{
|
||||
if (exp3.Arguments[a].Type != typeof(ExpressionCallContext))
|
||||
exp3InvokeParams[a] = exp3.Arguments[a].Type.CreateInstanceGetDefaultValue();
|
||||
exp3InvokeParams[a] = Utils.GetDataReaderValue(exp3.Arguments[a].Type, ecc.Values[exp3MethodParams[a].Name]);// exp3.Arguments[a].Type.CreateInstanceGetDefaultValue();
|
||||
else
|
||||
exp3InvokeParams[a] = ecc;
|
||||
}
|
||||
@ -1321,13 +1328,13 @@ namespace FreeSql.Internal
|
||||
public string formatSql(object obj, Type mapType, ColumnInfo mapColumn, List<DbParameter> dbParams)
|
||||
{
|
||||
//参数化设置,日后优化
|
||||
//if (dbParams != null && mapColumn != null)
|
||||
//{
|
||||
// var paramName = $"exp_{dbParams.Count}";
|
||||
// var parm = _common.AppendParamter(dbParams, paramName, mapColumn, mapType ?? mapColumn.Attribute.MapType, mapType == null ? obj : Utils.GetDataReaderValue(mapType, obj));
|
||||
// _common.SetParameterSize(parm, mapColumn.Attribute.DbType, mapColumn);
|
||||
// return _common.QuoteParamterName(paramName);
|
||||
//}
|
||||
if (dbParams != null)
|
||||
{
|
||||
var paramName = $"exp_{dbParams.Count}";
|
||||
var parm = _common.AppendParamter(dbParams, paramName, mapColumn,
|
||||
mapType ?? mapColumn?.Attribute.MapType ?? obj?.GetType(), mapType == null ? obj : Utils.GetDataReaderValue(mapType, obj));
|
||||
return _common.QuoteParamterName(paramName);
|
||||
}
|
||||
return string.Concat(_ado.AddslashesProcessParam(obj, mapType, mapColumn));
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
public bool IsSyncStructureToUpper { get; set; } = false;
|
||||
public bool IsConfigEntityFromDbFirst { get; set; } = false;
|
||||
public virtual bool IsNoneCommandParameter { get; set; } = false;
|
||||
public virtual bool IsGenerateCommandParameterWithLambda { get; set; } = false;
|
||||
public bool IsLazyLoading { get; set; } = false;
|
||||
|
||||
public abstract (int type, string dbtype, string dbtypeFull, bool? isnullable, object defaultValue)? GetDbInfo(Type type);
|
||||
|
@ -22,7 +22,6 @@ namespace FreeSql.Internal.CommonProvider
|
||||
protected int _whereTimes = 0;
|
||||
protected List<GlobalFilter.Item> _whereGlobalFilter;
|
||||
protected List<DbParameter> _params = new List<DbParameter>();
|
||||
protected bool _noneParameter;
|
||||
protected DbTransaction _transaction;
|
||||
protected DbConnection _connection;
|
||||
|
||||
@ -32,7 +31,6 @@ namespace FreeSql.Internal.CommonProvider
|
||||
_commonUtils = commonUtils;
|
||||
_commonExpression = commonExpression;
|
||||
_table = _commonUtils.GetTableByEntity(typeof(T1));
|
||||
_noneParameter = _orm.CodeFirst.IsNoneCommandParameter;
|
||||
this.Where(_commonUtils.WhereObject(_table, "", dywhere));
|
||||
if (_orm.CodeFirst.IsAutoSyncStructure && typeof(T1) != typeof(object)) _orm.CodeFirst.SyncStructure<T1>();
|
||||
_whereGlobalFilter = _orm.GlobalFilter.GetFilters();
|
||||
@ -87,7 +85,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
public abstract List<T1> ExecuteDeleted();
|
||||
|
||||
public IDelete<T1> Where(Expression<Func<T1, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, exp?.Body, null, _noneParameter ? _params : null));
|
||||
public IDelete<T1> Where(Expression<Func<T1, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, exp?.Body, null, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
public IDelete<T1> Where(string sql, object parms = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(sql)) return this;
|
||||
|
@ -35,7 +35,6 @@ namespace FreeSql.Internal.CommonProvider
|
||||
protected Action<object> _trackToList;
|
||||
protected List<Action<object>> _includeToList = new List<Action<object>>();
|
||||
protected bool _distinct;
|
||||
protected bool _noneParameter;
|
||||
protected Expression _selectExpression;
|
||||
protected List<LambdaExpression> _whereCascadeExpression = new List<LambdaExpression>();
|
||||
protected List<GlobalFilter.Item> _whereGlobalFilter;
|
||||
@ -106,7 +105,6 @@ namespace FreeSql.Internal.CommonProvider
|
||||
toType.GetField("_trackToList", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._trackToList);
|
||||
toType.GetField("_includeToList", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._includeToList);
|
||||
toType.GetField("_distinct", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._distinct);
|
||||
toType.GetField("_noneParameter", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._noneParameter);
|
||||
toType.GetField("_selectExpression", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._selectExpression);
|
||||
toType.GetField("_whereCascadeExpression", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._whereCascadeExpression);
|
||||
toType.GetField("_whereGlobalFilter", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._whereGlobalFilter);
|
||||
@ -118,7 +116,6 @@ namespace FreeSql.Internal.CommonProvider
|
||||
_commonUtils = commonUtils;
|
||||
_commonExpression = commonExpression;
|
||||
_tables.Add(new SelectTableInfo { Table = _commonUtils.GetTableByEntity(typeof(T1)), Alias = "a", On = null, Type = SelectTableInfoType.From });
|
||||
_noneParameter = _orm.CodeFirst.IsNoneCommandParameter;
|
||||
this.Where(_commonUtils.WhereObject(_tables.First().Table, "a.", dywhere));
|
||||
if (_orm.CodeFirst.IsAutoSyncStructure && typeof(T1) != typeof(object)) _orm.CodeFirst.SyncStructure<T1>();
|
||||
}
|
||||
@ -1054,7 +1051,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this.ToListMapReader<TReturn>((map, field.Length > 0 ? field.Remove(0, 2).ToString() : null)).FirstOrDefault();
|
||||
}
|
||||
|
||||
protected TSelect InternalWhere(Expression exp) => exp == null ? this as TSelect : this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp, null, _whereCascadeExpression, _noneParameter ? _params : null));
|
||||
protected TSelect InternalWhere(Expression exp) => exp == null ? this as TSelect : this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
#endregion
|
||||
|
||||
#if net40
|
||||
|
@ -153,21 +153,21 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (exp == null) return this.Where(null);
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null));
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
}
|
||||
|
||||
ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>.WhereIf(bool condition, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>> exp)
|
||||
{
|
||||
if (condition == false || exp == null) return this.Where(null);
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return condition ? this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)) : this;
|
||||
return condition ? this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)) : this;
|
||||
}
|
||||
|
||||
bool ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>.Any(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>> exp)
|
||||
{
|
||||
if (exp == null) return this.Any();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)).Any();
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)).Any();
|
||||
}
|
||||
|
||||
#if net40
|
||||
@ -226,7 +226,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (exp == null) return this.AnyAsync();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)).AnyAsync();
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)).AnyAsync();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -543,23 +543,48 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
var t1parm = Expression.Parameter(typeof(T1));
|
||||
Expression membersExp = t1parm;
|
||||
foreach (var mem in members) membersExp = Expression.MakeMemberAccess(membersExp, mem.Member);
|
||||
Expression membersExpNotNull = null;
|
||||
foreach (var mem in members)
|
||||
{
|
||||
membersExp = Expression.MakeMemberAccess(membersExp, mem.Member);
|
||||
var expNotNull = Expression.NotEqual(membersExp, Expression.Constant(null));
|
||||
if (membersExpNotNull == null) membersExpNotNull = expNotNull;
|
||||
else membersExpNotNull = Expression.AndAlso(membersExpNotNull, expNotNull);
|
||||
}
|
||||
members.Clear();
|
||||
|
||||
var listValueExp = Expression.Parameter(typeof(List<TNavigate>), "listValue");
|
||||
var setListValue = Expression.Lambda<Action<T1, List<TNavigate>>>(
|
||||
Expression.Assign(
|
||||
Expression.MakeMemberAccess(membersExp, collMem.Member),
|
||||
Expression.TypeAs(listValueExp, collMem.Type)
|
||||
), t1parm, listValueExp).Compile();
|
||||
var setListValue = membersExpNotNull == null ?
|
||||
Expression.Lambda<Action<T1, List<TNavigate>>>(
|
||||
Expression.Assign(
|
||||
Expression.MakeMemberAccess(membersExp, collMem.Member),
|
||||
Expression.TypeAs(listValueExp, collMem.Type)
|
||||
), t1parm, listValueExp).Compile() :
|
||||
Expression.Lambda<Action<T1, List<TNavigate>>>(
|
||||
Expression.IfThen(
|
||||
membersExpNotNull,
|
||||
Expression.Assign(
|
||||
Expression.MakeMemberAccess(membersExp, collMem.Member),
|
||||
Expression.TypeAs(listValueExp, collMem.Type)
|
||||
)
|
||||
), t1parm, listValueExp).Compile();
|
||||
|
||||
var returnTarget = Expression.Label(typeof(object));
|
||||
var propertyNameExp = Expression.Parameter(typeof(string), "propertyName");
|
||||
var getListValue1 = Expression.Lambda<Func<T1, string, object>>(
|
||||
Expression.Block(
|
||||
Expression.Return(returnTarget, Expression.Call(null, GetEntityValueWithPropertyNameMethod, Expression.Constant(_orm), Expression.Constant(membersExp.Type), membersExp, propertyNameExp)),
|
||||
Expression.Label(returnTarget, Expression.Default(typeof(object)))
|
||||
), t1parm, propertyNameExp).Compile();
|
||||
var getListValue1 = membersExpNotNull == null ?
|
||||
Expression.Lambda<Func<T1, string, object>>(
|
||||
Expression.Block(
|
||||
Expression.Return(returnTarget, Expression.Call(null, GetEntityValueWithPropertyNameMethod, Expression.Constant(_orm), Expression.Constant(membersExp.Type), membersExp, propertyNameExp)),
|
||||
Expression.Label(returnTarget, Expression.Default(typeof(object)))
|
||||
), t1parm, propertyNameExp).Compile():
|
||||
Expression.Lambda<Func<T1, string, object>>(
|
||||
Expression.Block(
|
||||
Expression.IfThen(
|
||||
membersExpNotNull,
|
||||
Expression.Return(returnTarget, Expression.Call(null, GetEntityValueWithPropertyNameMethod, Expression.Constant(_orm), Expression.Constant(membersExp.Type), membersExp, propertyNameExp))
|
||||
),
|
||||
Expression.Label(returnTarget, Expression.Default(typeof(object)))
|
||||
), t1parm, propertyNameExp).Compile();
|
||||
|
||||
var getListValue2 = new List<Func<T1, string, object>>();
|
||||
for (var j = 0; j < tbrefOneToManyColumns.Count; j++)
|
||||
@ -570,13 +595,29 @@ namespace FreeSql.Internal.CommonProvider
|
||||
continue;
|
||||
}
|
||||
Expression tbrefOneToManyColumnsMembers = t1parm;
|
||||
foreach (var mem in tbrefOneToManyColumns[j]) tbrefOneToManyColumnsMembers = Expression.MakeMemberAccess(tbrefOneToManyColumnsMembers, mem.Member);
|
||||
Expression tbrefOneToManyColumnsMembersNotNull = null;
|
||||
foreach (var mem in tbrefOneToManyColumns[j])
|
||||
{
|
||||
tbrefOneToManyColumnsMembers = Expression.MakeMemberAccess(tbrefOneToManyColumnsMembers, mem.Member);
|
||||
var expNotNull = Expression.NotEqual(membersExp, Expression.Constant(null));
|
||||
if (tbrefOneToManyColumnsMembersNotNull == null) tbrefOneToManyColumnsMembersNotNull = expNotNull;
|
||||
else tbrefOneToManyColumnsMembersNotNull = Expression.AndAlso(tbrefOneToManyColumnsMembersNotNull, expNotNull);
|
||||
}
|
||||
tbrefOneToManyColumns[j].Clear();
|
||||
getListValue2.Add(Expression.Lambda<Func<T1, string, object>>(
|
||||
Expression.Block(
|
||||
Expression.Return(returnTarget, Expression.Call(null, GetEntityValueWithPropertyNameMethod, Expression.Constant(_orm), Expression.Constant(tbrefOneToManyColumnsMembers.Type), tbrefOneToManyColumnsMembers, propertyNameExp)),
|
||||
Expression.Label(returnTarget, Expression.Default(typeof(object)))
|
||||
), t1parm, propertyNameExp).Compile());
|
||||
getListValue2.Add(tbrefOneToManyColumnsMembersNotNull == null ?
|
||||
Expression.Lambda<Func<T1, string, object>>(
|
||||
Expression.Block(
|
||||
Expression.Return(returnTarget, Expression.Call(null, GetEntityValueWithPropertyNameMethod, Expression.Constant(_orm), Expression.Constant(tbrefOneToManyColumnsMembers.Type), tbrefOneToManyColumnsMembers, propertyNameExp)),
|
||||
Expression.Label(returnTarget, Expression.Default(typeof(object)))
|
||||
), t1parm, propertyNameExp).Compile() :
|
||||
Expression.Lambda<Func<T1, string, object>>(
|
||||
Expression.Block(
|
||||
Expression.IfThen(
|
||||
tbrefOneToManyColumnsMembersNotNull,
|
||||
Expression.Return(returnTarget, Expression.Call(null, GetEntityValueWithPropertyNameMethod, Expression.Constant(_orm), Expression.Constant(tbrefOneToManyColumnsMembers.Type), tbrefOneToManyColumnsMembers, propertyNameExp))
|
||||
),
|
||||
Expression.Label(returnTarget, Expression.Default(typeof(object)))
|
||||
), t1parm, propertyNameExp).Compile());
|
||||
}
|
||||
tbrefOneToManyColumns.Clear();
|
||||
Func<T1, string, int, object> getListValue = (item, propName, colIndex) =>
|
||||
@ -706,7 +747,8 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (tbref.Columns.Count == 1)
|
||||
{
|
||||
var dicListKey = getListValue(item, tbref.Columns[0].CsName, 0).ToString();
|
||||
var dicListKey = getListValue(item, tbref.Columns[0].CsName, 0)?.ToString();
|
||||
if (dicListKey == null) continue;
|
||||
var dicListVal = Tuple.Create(item, new List<TNavigate>());
|
||||
if (dicList.TryGetValue(dicListKey, out var items) == false)
|
||||
dicList.Add(dicListKey, items = new List<Tuple<T1, List<TNavigate>>>());
|
||||
@ -891,7 +933,8 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (tbref.Columns.Count == 1)
|
||||
{
|
||||
var dicListKey = getListValue1(item, tbref.Columns[0].CsName).ToString();
|
||||
var dicListKey = getListValue1(item, tbref.Columns[0].CsName)?.ToString();
|
||||
if (dicListKey == null) continue;
|
||||
var dicListVal = Tuple.Create(item, new List<TNavigate>());
|
||||
if (dicList.TryGetValue(dicListKey, out var items) == false)
|
||||
dicList.Add(dicListKey, items = new List<Tuple<T1, List<TNavigate>>>());
|
||||
|
@ -130,21 +130,21 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (exp == null) return this.Where(null);
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null));
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
}
|
||||
|
||||
ISelect<T1, T2> ISelect<T1, T2>.WhereIf(bool condition, Expression<Func<T1, T2, bool>> exp)
|
||||
{
|
||||
if (condition == false || exp == null) return this;
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null));
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
}
|
||||
|
||||
bool ISelect<T1, T2>.Any(Expression<Func<T1, T2, bool>> exp)
|
||||
{
|
||||
if (exp == null) return this.Any();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)).Any();
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)).Any();
|
||||
}
|
||||
|
||||
#if net40
|
||||
@ -203,7 +203,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (exp == null) return this.AnyAsync();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)).AnyAsync();
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)).AnyAsync();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -133,21 +133,21 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (exp == null) return this.Where(null);
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null));
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
}
|
||||
|
||||
ISelect<T1, T2, T3> ISelect<T1, T2, T3>.WhereIf(bool condition, Expression<Func<T1, T2, T3, bool>> exp)
|
||||
{
|
||||
if (condition == false || exp == null) return this;
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null));
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
}
|
||||
|
||||
bool ISelect<T1, T2, T3>.Any(Expression<Func<T1, T2, T3, bool>> exp)
|
||||
{
|
||||
if (exp == null) return this.Any();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)).Any();
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)).Any();
|
||||
}
|
||||
|
||||
#if net40
|
||||
@ -206,7 +206,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (exp == null) return this.AnyAsync();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)).AnyAsync();
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)).AnyAsync();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -136,21 +136,21 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (exp == null) return this.Where(null);
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null));
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
}
|
||||
|
||||
ISelect<T1, T2, T3, T4> ISelect<T1, T2, T3, T4>.WhereIf(bool condition, Expression<Func<T1, T2, T3, T4, bool>> exp)
|
||||
{
|
||||
if (condition == false || exp == null) return this;
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null));
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
}
|
||||
|
||||
bool ISelect<T1, T2, T3, T4>.Any(Expression<Func<T1, T2, T3, T4, bool>> exp)
|
||||
{
|
||||
if (exp == null) return this.Any();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)).Any();
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)).Any();
|
||||
}
|
||||
|
||||
#if net40
|
||||
@ -209,7 +209,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (exp == null) return this.AnyAsync();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)).AnyAsync();
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)).AnyAsync();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -139,21 +139,21 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (exp == null) return this.Where(null);
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null));
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
}
|
||||
|
||||
ISelect<T1, T2, T3, T4, T5> ISelect<T1, T2, T3, T4, T5>.WhereIf(bool condition, Expression<Func<T1, T2, T3, T4, T5, bool>> exp)
|
||||
{
|
||||
if (condition == false || exp == null) return this;
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null));
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
}
|
||||
|
||||
bool ISelect<T1, T2, T3, T4, T5>.Any(Expression<Func<T1, T2, T3, T4, T5, bool>> exp)
|
||||
{
|
||||
if (exp == null) return this.Any();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)).Any();
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)).Any();
|
||||
}
|
||||
|
||||
#if net40
|
||||
@ -212,7 +212,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (exp == null) return this.AnyAsync();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)).AnyAsync();
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)).AnyAsync();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -142,21 +142,21 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (exp == null) return this.Where(null);
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null));
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
}
|
||||
|
||||
ISelect<T1, T2, T3, T4, T5, T6> ISelect<T1, T2, T3, T4, T5, T6>.WhereIf(bool condition, Expression<Func<T1, T2, T3, T4, T5, T6, bool>> exp)
|
||||
{
|
||||
if (condition == false || exp == null) return this;
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null));
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
}
|
||||
|
||||
bool ISelect<T1, T2, T3, T4, T5, T6>.Any(Expression<Func<T1, T2, T3, T4, T5, T6, bool>> exp)
|
||||
{
|
||||
if (exp == null) return this.Any();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)).Any();
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)).Any();
|
||||
}
|
||||
|
||||
#if net40
|
||||
@ -215,7 +215,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (exp == null) return this.AnyAsync();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)).AnyAsync();
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)).AnyAsync();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -145,21 +145,21 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (exp == null) return this.Where(null);
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null));
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
}
|
||||
|
||||
ISelect<T1, T2, T3, T4, T5, T6, T7> ISelect<T1, T2, T3, T4, T5, T6, T7>.WhereIf(bool condition, Expression<Func<T1, T2, T3, T4, T5, T6, T7, bool>> exp)
|
||||
{
|
||||
if (condition == false || exp == null) return this;
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null));
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
}
|
||||
|
||||
bool ISelect<T1, T2, T3, T4, T5, T6, T7>.Any(Expression<Func<T1, T2, T3, T4, T5, T6, T7, bool>> exp)
|
||||
{
|
||||
if (exp == null) return this.Any();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)).Any();
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)).Any();
|
||||
}
|
||||
|
||||
#if net40
|
||||
@ -218,7 +218,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (exp == null) return this.AnyAsync();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)).AnyAsync();
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)).AnyAsync();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -149,21 +149,21 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (exp == null) return this.Where(null);
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null));
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
}
|
||||
|
||||
ISelect<T1, T2, T3, T4, T5, T6, T7, T8> ISelect<T1, T2, T3, T4, T5, T6, T7, T8>.WhereIf(bool condition, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, bool>> exp)
|
||||
{
|
||||
if (condition == false || exp == null) return this;
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null));
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
}
|
||||
|
||||
bool ISelect<T1, T2, T3, T4, T5, T6, T7, T8>.Any(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, bool>> exp)
|
||||
{
|
||||
if (exp == null) return this.Any();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)).Any();
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)).Any();
|
||||
}
|
||||
|
||||
#if net40
|
||||
@ -222,7 +222,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (exp == null) return this.AnyAsync();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)).AnyAsync();
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)).AnyAsync();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -147,20 +147,20 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (exp == null) return this.Where(null);
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null));
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
}
|
||||
ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.WhereIf(bool condition, Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, bool>> exp)
|
||||
{
|
||||
if (condition == false || exp == null) return this;
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null));
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
}
|
||||
|
||||
bool ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.Any(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, bool>> exp)
|
||||
{
|
||||
if (exp == null) return this.Any();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)).Any();
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)).Any();
|
||||
}
|
||||
|
||||
#if net40
|
||||
@ -169,7 +169,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
if (exp == null) return this.AnyAsync();
|
||||
for (var a = 0; a < exp.Parameters.Count; a++) _tables[a].Parameter = exp.Parameters[a];
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _noneParameter ? _params : null)).AnyAsync();
|
||||
return this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null, _whereCascadeExpression, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null)).AnyAsync();
|
||||
}
|
||||
|
||||
Task<DataTable> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select)
|
||||
|
@ -424,7 +424,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this;
|
||||
}
|
||||
|
||||
public IUpdate<T1> Where(Expression<Func<T1, bool>> expression) => this.Where(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, expression?.Body, null, _noneParameter ? _params : null));
|
||||
public IUpdate<T1> Where(Expression<Func<T1, bool>> expression) => this.Where(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, expression?.Body, null, _orm.CodeFirst.IsGenerateCommandParameterWithLambda ? _params : null));
|
||||
public IUpdate<T1> Where(string sql, object parms = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(sql)) return this;
|
||||
|
@ -48,25 +48,6 @@ namespace FreeSql.Internal
|
||||
_orm = orm;
|
||||
}
|
||||
|
||||
static Regex _regexSize = new Regex(@"\(([^\)]+)\)", RegexOptions.Compiled);
|
||||
internal void SetParameterSize(DbParameter parm, string dbtypeFull, ColumnInfo col)
|
||||
{
|
||||
if (col == null) return;
|
||||
if (string.IsNullOrEmpty(dbtypeFull)) return;
|
||||
var m = _regexSize.Match(dbtypeFull);
|
||||
if (m.Success == false) return;
|
||||
var sizeStr = m.Groups[1].Value.Trim();
|
||||
if (string.Compare(sizeStr, "max", true) == 0)
|
||||
{
|
||||
parm.Size = -1;
|
||||
return;
|
||||
}
|
||||
var sizeArr = sizeStr.Split(',');
|
||||
if (int.TryParse(sizeArr[0], out var size) == false) return;
|
||||
if (sizeArr.Length > 1 && int.TryParse(sizeArr[1], out var size2)) size += size2;
|
||||
parm.Size = size;
|
||||
}
|
||||
|
||||
ConcurrentDictionary<Type, TableAttribute> dicConfigEntity = new ConcurrentDictionary<Type, TableAttribute>();
|
||||
public ICodeFirst ConfigEntity<T>(Action<TableFluent<T>> entity)
|
||||
{
|
||||
|
@ -13,6 +13,10 @@ namespace FreeSql.Internal.Model
|
||||
public Type CsType { get; set; }
|
||||
public ColumnAttribute Attribute { get; set; }
|
||||
public string Comment { get; internal set; }
|
||||
public string DbTypeText { get; internal set; }
|
||||
public int DbSize { get; internal set; }
|
||||
public byte DbPrecision { get; internal set; }
|
||||
public byte DbScale { get; internal set; }
|
||||
|
||||
static ConcurrentDictionary<ColumnInfo, Func<object, object>> _dicGetMapValue = new ConcurrentDictionary<ColumnInfo, Func<object, object>>();
|
||||
public object GetMapValue(object obj)
|
||||
|
@ -299,6 +299,34 @@ namespace FreeSql.Internal
|
||||
col.Attribute.IsNullable = false;
|
||||
col.Attribute.DbType = col.Attribute.DbType.Replace("NOT NULL", "");
|
||||
}
|
||||
foreach (var col in trytb.Columns.Values)
|
||||
{
|
||||
var ltp = @"\(([^\)]+)\)";
|
||||
col.DbTypeText = Regex.Replace(col.Attribute.DbType.Replace("NOT NULL", "").Trim(), ltp, "");
|
||||
var m = Regex.Match(col.Attribute.DbType, ltp);
|
||||
if (m.Success == false) continue;
|
||||
var sizeStr = m.Groups[1].Value.Trim();
|
||||
if (string.Compare(sizeStr, "max", true) == 0)
|
||||
{
|
||||
col.DbSize = -1;
|
||||
continue;
|
||||
}
|
||||
var sizeArr = sizeStr.Split(',');
|
||||
if (int.TryParse(sizeArr[0].Trim(), out var size) == false) continue;
|
||||
if (col.Attribute.MapType.NullableTypeOrThis() == typeof(DateTime))
|
||||
{
|
||||
col.DbScale = (byte)size;
|
||||
continue;
|
||||
}
|
||||
if (sizeArr.Length == 1)
|
||||
{
|
||||
col.DbSize = size;
|
||||
continue;
|
||||
}
|
||||
if (byte.TryParse(sizeArr[1], out var scale) == false) continue;
|
||||
col.DbPrecision = (byte)size;
|
||||
col.DbScale = scale;
|
||||
}
|
||||
tbc.AddOrUpdate(entity, trytb, (oldkey, oldval) => trytb);
|
||||
|
||||
#region 查找导航属性的关系、virtual 属性延时加载,动态产生新的重写类
|
||||
|
@ -21,26 +21,31 @@ namespace FreeSql.MySql
|
||||
public override DbParameter AppendParamter(List<DbParameter> _params, string parameterName, ColumnInfo col, Type type, object value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
|
||||
if (type == null && col != null) type = col.Attribute.MapType ?? col.CsType;
|
||||
var ret = new MySqlParameter { ParameterName = QuoteParamterName(parameterName), Value = value };
|
||||
var tp = _orm.CodeFirst.GetDbInfo(type)?.type;
|
||||
if (tp != null)
|
||||
var dbtype = (MySqlDbType)_orm.CodeFirst.GetDbInfo(type)?.type;
|
||||
if (col != null)
|
||||
{
|
||||
if (col != null && type == typeof(string))
|
||||
var dbtype2 = (MySqlDbType)_orm.DbFirst.GetDbType(new DatabaseModel.DbColumnInfo { DbTypeText = col.DbTypeText, DbTypeTextFull = col.Attribute.DbType, MaxLength = col.DbSize });
|
||||
switch (dbtype2)
|
||||
{
|
||||
if (col.Attribute.DbType.Contains("VARCHAR")) ret.MySqlDbType = MySqlDbType.VarChar;
|
||||
else if (col.Attribute.DbType.Contains("CHAR")) ret.MySqlDbType = MySqlDbType.VarChar;
|
||||
else if (col.Attribute.DbType.Contains("TEXT")) ret.MySqlDbType = MySqlDbType.Text;
|
||||
else ret.MySqlDbType = MySqlDbType.VarChar;
|
||||
case MySqlDbType.Binary:
|
||||
case MySqlDbType.VarBinary:
|
||||
break;
|
||||
default:
|
||||
dbtype = dbtype2;
|
||||
if (col.DbSize != 0) ret.Size = col.DbSize;
|
||||
if (col.DbPrecision != 0) ret.Precision = col.DbPrecision;
|
||||
if (col.DbScale != 0) ret.Scale = col.DbScale;
|
||||
break;
|
||||
}
|
||||
else if ((MySqlDbType)tp.Value == MySqlDbType.Geometry)
|
||||
{
|
||||
ret.MySqlDbType = MySqlDbType.Text;
|
||||
if (value != null) ret.Value = (value as MygisGeometry).AsText();
|
||||
}
|
||||
else
|
||||
ret.MySqlDbType = (MySqlDbType)tp.Value;
|
||||
}
|
||||
if (dbtype == MySqlDbType.Geometry)
|
||||
{
|
||||
ret.MySqlDbType = MySqlDbType.Text;
|
||||
if (value != null) ret.Value = (value as MygisGeometry).AsText();
|
||||
}
|
||||
else
|
||||
ret.MySqlDbType = dbtype;
|
||||
_params?.Add(ret);
|
||||
return ret;
|
||||
}
|
||||
|
@ -21,30 +21,35 @@ namespace FreeSql.MySql
|
||||
public override DbParameter AppendParamter(List<DbParameter> _params, string parameterName, ColumnInfo col, Type type, object value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
|
||||
if (type == null && col != null) type = col.Attribute.MapType ?? col.CsType;
|
||||
var ret = new MySqlParameter { ParameterName = QuoteParamterName(parameterName), Value = value };
|
||||
var tp = _orm.CodeFirst.GetDbInfo(type)?.type;
|
||||
if (tp != null)
|
||||
var dbtype = (MySqlDbType)_orm.CodeFirst.GetDbInfo(type)?.type;
|
||||
if (col != null)
|
||||
{
|
||||
if (col != null && type == typeof(string))
|
||||
var dbtype2 = (MySqlDbType)_orm.DbFirst.GetDbType(new DatabaseModel.DbColumnInfo { DbTypeText = col.DbTypeText, DbTypeTextFull = col.Attribute.DbType, MaxLength = col.DbSize });
|
||||
switch (dbtype2)
|
||||
{
|
||||
if (col.Attribute.DbType.Contains("VARCHAR")) ret.MySqlDbType = MySqlDbType.VarChar;
|
||||
else if (col.Attribute.DbType.Contains("CHAR")) ret.MySqlDbType = MySqlDbType.VarChar;
|
||||
else if (col.Attribute.DbType.Contains("TEXT")) ret.MySqlDbType = MySqlDbType.Text;
|
||||
else ret.MySqlDbType = MySqlDbType.VarChar;
|
||||
}
|
||||
else if ((MySqlDbType)tp.Value == MySqlDbType.Geometry)
|
||||
{
|
||||
ret.MySqlDbType = MySqlDbType.Text;
|
||||
if (value != null) ret.Value = (value as MygisGeometry).AsText();
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.MySqlDbType = (MySqlDbType)tp.Value;
|
||||
if (ret.MySqlDbType == MySqlDbType.Enum && value != null)
|
||||
ret.Value = (long)Convert.ChangeType(value, typeof(long)) + 1;
|
||||
//case MySqlDbType.Binary:
|
||||
//case MySqlDbType.VarBinary:
|
||||
// break;
|
||||
default:
|
||||
dbtype = dbtype2;
|
||||
if (col.DbSize != 0) ret.Size = col.DbSize;
|
||||
if (col.DbPrecision != 0) ret.Precision = col.DbPrecision;
|
||||
if (col.DbScale != 0) ret.Scale = col.DbScale;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dbtype == MySqlDbType.Geometry)
|
||||
{
|
||||
ret.MySqlDbType = MySqlDbType.Text;
|
||||
if (value != null) ret.Value = (value as MygisGeometry).AsText();
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.MySqlDbType = dbtype;
|
||||
if (ret.MySqlDbType == MySqlDbType.Enum && value != null)
|
||||
ret.Value = (long)Convert.ChangeType(value, typeof(long)) + 1;
|
||||
}
|
||||
_params?.Add(ret);
|
||||
return ret;
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ namespace FreeSql.Odbc.Default
|
||||
public override DbParameter AppendParamter(List<DbParameter> _params, string parameterName, ColumnInfo col, Type type, object value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
|
||||
if (type == null && col != null) type = col.Attribute.MapType ?? col.CsType;
|
||||
if (value?.Equals(DateTime.MinValue) == true) value = new DateTime(1970, 1, 1);
|
||||
var ret = new OdbcParameter { ParameterName = QuoteParamterName(parameterName), Value = value };
|
||||
var tp = _orm.CodeFirst.GetDbInfo(type)?.type;
|
||||
|
@ -21,7 +21,6 @@ namespace FreeSql.Odbc.MySql
|
||||
public override DbParameter AppendParamter(List<DbParameter> _params, string parameterName, ColumnInfo col, Type type, object value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
|
||||
if (type == null && col != null) type = col.Attribute.MapType ?? col.CsType;
|
||||
var ret = new OdbcParameter { ParameterName = QuoteParamterName(parameterName), Value = value };
|
||||
var tp = _orm.CodeFirst.GetDbInfo(type)?.type;
|
||||
if (tp != null)
|
||||
|
@ -19,7 +19,6 @@ namespace FreeSql.Odbc.Oracle
|
||||
public override DbParameter AppendParamter(List<DbParameter> _params, string parameterName, ColumnInfo col, Type type, object value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
|
||||
if (type == null && col != null) type = col.Attribute.MapType ?? col.CsType;
|
||||
var dbtype = (OdbcType)_orm.CodeFirst.GetDbInfo(type)?.type;
|
||||
switch (dbtype)
|
||||
{
|
||||
|
@ -67,7 +67,6 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
public override DbParameter AppendParamter(List<DbParameter> _params, string parameterName, ColumnInfo col, Type type, object value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
|
||||
if (type == null && col != null) type = col.Attribute.MapType ?? col.CsType;
|
||||
if (value != null) value = getParamterValue(type, value);
|
||||
var ret = new OdbcParameter { ParameterName = QuoteParamterName(parameterName), Value = value };
|
||||
//if (value.GetType().IsEnum || value.GetType().GenericTypeArguments.FirstOrDefault()?.IsEnum == true) {
|
||||
|
@ -25,7 +25,6 @@ namespace FreeSql.Odbc.SqlServer
|
||||
public override DbParameter AppendParamter(List<DbParameter> _params, string parameterName, ColumnInfo col, Type type, object value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
|
||||
if (type == null && col != null) type = col.Attribute.MapType ?? col.CsType;
|
||||
if (value?.Equals(DateTime.MinValue) == true) value = new DateTime(1970, 1, 1);
|
||||
var ret = new OdbcParameter { ParameterName = QuoteParamterName(parameterName), Value = value };
|
||||
var tp = _orm.CodeFirst.GetDbInfo(type)?.type;
|
||||
|
@ -19,7 +19,6 @@ namespace FreeSql.Oracle
|
||||
public override DbParameter AppendParamter(List<DbParameter> _params, string parameterName, ColumnInfo col, Type type, object value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
|
||||
if (type == null && col != null) type = col.Attribute.MapType ?? col.CsType;
|
||||
var dbtype = (OracleDbType)_orm.CodeFirst.GetDbInfo(type)?.type;
|
||||
if (dbtype == OracleDbType.Boolean)
|
||||
{
|
||||
@ -27,15 +26,24 @@ namespace FreeSql.Oracle
|
||||
else value = (bool)value == true ? 1 : 0;
|
||||
dbtype = OracleDbType.Int16;
|
||||
}
|
||||
else if (col != null && type == typeof(string))
|
||||
{
|
||||
if (col.Attribute.DbType.Contains("NVARCHAR2")) dbtype = OracleDbType.NVarchar2;
|
||||
else if (col.Attribute.DbType.Contains("VARCHAR2")) dbtype = OracleDbType.Varchar2;
|
||||
else if (col.Attribute.DbType.Contains("NCHAR")) dbtype = OracleDbType.NChar;
|
||||
else if (col.Attribute.DbType.Contains("CHAR")) dbtype = OracleDbType.Char;
|
||||
else dbtype = OracleDbType.NVarchar2;
|
||||
}
|
||||
var ret = new OracleParameter { ParameterName = QuoteParamterName(parameterName), OracleDbType = dbtype, Value = value };
|
||||
if (col != null)
|
||||
{
|
||||
var dbtype2 = (OracleDbType)_orm.DbFirst.GetDbType(new DatabaseModel.DbColumnInfo { DbTypeTextFull = col.Attribute.DbType.Replace("NOT NULL", "").Trim(), DbTypeText = col.DbTypeText });
|
||||
switch (dbtype2)
|
||||
{
|
||||
case OracleDbType.Char:
|
||||
case OracleDbType.Varchar2:
|
||||
case OracleDbType.NChar:
|
||||
case OracleDbType.NVarchar2:
|
||||
case OracleDbType.Decimal:
|
||||
dbtype = dbtype2;
|
||||
if (col.DbSize != 0) ret.Size = col.DbSize;
|
||||
if (col.DbPrecision != 0) ret.Precision = col.DbPrecision;
|
||||
if (col.DbScale != 0) ret.Scale = col.DbScale;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_params?.Add(ret);
|
||||
return ret;
|
||||
}
|
||||
|
@ -82,24 +82,23 @@ namespace FreeSql.PostgreSQL
|
||||
public override DbParameter AppendParamter(List<DbParameter> _params, string parameterName, ColumnInfo col, Type type, object value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
|
||||
if (type == null && col != null) type = col.Attribute.MapType ?? col.CsType;
|
||||
if (value != null) value = getParamterValue(type, value);
|
||||
var ret = new NpgsqlParameter { ParameterName = QuoteParamterName(parameterName), Value = value };
|
||||
//if (value.GetType().IsEnum || value.GetType().GenericTypeArguments.FirstOrDefault()?.IsEnum == true) {
|
||||
// ret.DataTypeName = "";
|
||||
//} else {
|
||||
var tp = _orm.CodeFirst.GetDbInfo(type)?.type;
|
||||
if (tp != null)
|
||||
if (tp != null) ret.NpgsqlDbType = (NpgsqlDbType)tp.Value;
|
||||
if (col != null)
|
||||
{
|
||||
if (col != null && type == typeof(string))
|
||||
var dbtype = (NpgsqlDbType)_orm.DbFirst.GetDbType(new DatabaseModel.DbColumnInfo { DbTypeText = col.DbTypeText });
|
||||
if (dbtype != NpgsqlDbType.Unknown)
|
||||
{
|
||||
if (col.Attribute.DbType.Contains("VARCHAR")) ret.NpgsqlDbType = NpgsqlDbType.Varchar;
|
||||
else if (col.Attribute.DbType.Contains("CHAR")) ret.NpgsqlDbType = NpgsqlDbType.Char;
|
||||
else if (col.Attribute.DbType.Contains("TEXT")) ret.NpgsqlDbType = NpgsqlDbType.Text;
|
||||
else ret.NpgsqlDbType = NpgsqlDbType.Varchar;
|
||||
ret.NpgsqlDbType = dbtype;
|
||||
if (col.DbSize != 0) ret.Size = col.DbSize;
|
||||
if (col.DbPrecision != 0) ret.Precision = col.DbPrecision;
|
||||
if (col.DbScale != 0) ret.Scale = col.DbScale;
|
||||
}
|
||||
else
|
||||
ret.NpgsqlDbType = (NpgsqlDbType)tp.Value;
|
||||
}
|
||||
//}
|
||||
_params?.Add(ret);
|
||||
|
@ -25,24 +25,20 @@ namespace FreeSql.SqlServer
|
||||
public override DbParameter AppendParamter(List<DbParameter> _params, string parameterName, ColumnInfo col, Type type, object value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
|
||||
if (type == null && col != null) type = col.Attribute.MapType ?? col.CsType;
|
||||
if (value?.Equals(DateTime.MinValue) == true) value = new DateTime(1970, 1, 1);
|
||||
var ret = new SqlParameter { ParameterName = QuoteParamterName(parameterName), Value = value };
|
||||
var tp = _orm.CodeFirst.GetDbInfo(type)?.type;
|
||||
if (tp != null)
|
||||
if (tp != null) ret.SqlDbType = (SqlDbType)tp.Value;
|
||||
if (col != null)
|
||||
{
|
||||
if (col != null && type == typeof(string))
|
||||
var dbtype = (SqlDbType)_orm.DbFirst.GetDbType(new DatabaseModel.DbColumnInfo { DbTypeText = col.DbTypeText });
|
||||
if (dbtype != SqlDbType.Variant)
|
||||
{
|
||||
if (col.Attribute.DbType.Contains("NVARCHAR")) ret.SqlDbType = SqlDbType.NVarChar;
|
||||
else if (col.Attribute.DbType.Contains("VARCHAR")) ret.SqlDbType = SqlDbType.VarChar;
|
||||
else if (col.Attribute.DbType.Contains("NCHAR")) ret.SqlDbType = SqlDbType.NChar;
|
||||
else if (col.Attribute.DbType.Contains("CHAR")) ret.SqlDbType = SqlDbType.Char;
|
||||
else if (col.Attribute.DbType.Contains("NTEXT")) ret.SqlDbType = SqlDbType.NText;
|
||||
else if (col.Attribute.DbType.Contains("TEXT")) ret.SqlDbType = SqlDbType.Text;
|
||||
else ret.SqlDbType = SqlDbType.VarChar;
|
||||
ret.SqlDbType = dbtype;
|
||||
if (col.DbSize != 0) ret.Size = col.DbSize;
|
||||
if (col.DbPrecision != 0) ret.Precision = col.DbPrecision;
|
||||
if (col.DbScale != 0) ret.Scale = col.DbScale;
|
||||
}
|
||||
else
|
||||
ret.SqlDbType = (SqlDbType)tp.Value;
|
||||
}
|
||||
_params?.Add(ret);
|
||||
return ret;
|
||||
|
@ -19,7 +19,6 @@ namespace FreeSql.Sqlite
|
||||
public override DbParameter AppendParamter(List<DbParameter> _params, string parameterName, ColumnInfo col, Type type, object value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
|
||||
if (type == null && col != null) type = col.Attribute.MapType ?? col.CsType;
|
||||
var dbtype = (DbType)_orm.CodeFirst.GetDbInfo(type)?.type;
|
||||
switch (dbtype)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user