mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 修复 ISelect.InsertInto 设置别名时无法使用的错误;#576
This commit is contained in:
parent
ab130ac2dd
commit
b542edf121
@ -502,14 +502,5 @@
|
||||
<param name="that"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||
<summary>
|
||||
批量注入 Repository,可以参考代码自行调整
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
<param name="globalDataFilter"></param>
|
||||
<param name="assemblies"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
@ -139,6 +139,21 @@
|
||||
创建人名称
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Issues._576.SysRole.Guid">
|
||||
<summary>
|
||||
GUID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Issues._576.SysRole.RoleName">
|
||||
<summary>
|
||||
角色名称
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Issues._576.SysRole.Sort">
|
||||
<summary>
|
||||
角色排序
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.Tests.MySql.MySqlCodeFirstTest.Tb_alltype.Save">
|
||||
<summary>
|
||||
保存或添加,如果主键有值则尝试 Update,如果影响的行为 0 则尝试 Insert
|
||||
|
81
FreeSql.Tests/FreeSql.Tests/Issues/576.cs
Normal file
81
FreeSql.Tests/FreeSql.Tests/Issues/576.cs
Normal file
@ -0,0 +1,81 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Issues
|
||||
{
|
||||
public class _576
|
||||
{
|
||||
[ExpressionCall]
|
||||
public static class _576Extensions
|
||||
{
|
||||
public static ThreadLocal<ExpressionCallContext> expContext = new ThreadLocal<ExpressionCallContext>();
|
||||
|
||||
/// <summary>
|
||||
/// 自定义表达式树函数解析
|
||||
/// </summary>
|
||||
/// <param name="that"></param>
|
||||
/// <param name="withinCode"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToNormalWithinCodeGuid([RawValue] this Guid that, string withinCode)
|
||||
{
|
||||
expContext.Value.Result = $"{expContext.Value.ParsedContent["withinCode"]} || '{that.ToString("N")}'";
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsertInto()
|
||||
{
|
||||
IFreeSql fsql = g.oracle;
|
||||
|
||||
|
||||
fsql.Delete<SysRole>().Where("1=1").ExecuteAffrows();
|
||||
var id = Guid.NewGuid().ToString();
|
||||
fsql.Insert(new SysRole { Guid = id, RoleName = "role1", Sort = 1 }).ExecuteAffrows();
|
||||
|
||||
Assert.Equal(1, fsql.Select<SysRole>().Where(a => a.Guid == id).InsertInto("", a => new SysRole
|
||||
{
|
||||
Guid = "'x123123dasfafd'",
|
||||
RoleName = Guid.NewGuid().ToNormalWithinCodeGuid(a.RoleName),
|
||||
Sort = a.Sort
|
||||
}));
|
||||
|
||||
var item = fsql.Select<SysRole>().Where(a => a.Guid == "x123123dasfafd").First();
|
||||
Assert.NotNull(item);
|
||||
Assert.True(item.RoleName.StartsWith("role1") && item.RoleName.Length == 37);
|
||||
Assert.Equal(item.Sort, 1);
|
||||
}
|
||||
|
||||
[Table(Name = "issues_576_SysRole")]
|
||||
public partial class SysRole
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// GUID
|
||||
/// </summary>
|
||||
[JsonProperty, Column(Name = "GUID", DbType = "VARCHAR2(60 BYTE)", IsPrimary = true)]
|
||||
public string Guid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 角色名称
|
||||
/// </summary>
|
||||
[JsonProperty, Column(Name = "ROLE_NAME", DbType = "NVARCHAR2(40)")]
|
||||
public string RoleName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 角色排序
|
||||
/// </summary>
|
||||
[JsonProperty, Column(Name = "SORT")]
|
||||
public int Sort { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -786,7 +786,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
var selectField = string.Join(", ", childs.Select(a => a.DbField));
|
||||
var selectSql = this.ToSql(selectField);
|
||||
var insertField = string.Join(", ", childs.Select(a => _commonUtils.QuoteSqlName(tb.Columns[a.CsName].Attribute.Name)));
|
||||
var insertField = string.Join(", ", childs.Select(a => _commonUtils.QuoteSqlName(tb.ColumnsByCs[a.CsName].Attribute.Name)));
|
||||
var sql = $"INSERT INTO {_commonUtils.QuoteSqlName(tableName)}({insertField})\r\n{selectSql}";
|
||||
return sql;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user