|
| 1 | +using FreeSql.DataAnnotations; |
| 2 | +using Newtonsoft.Json; |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.ComponentModel; |
| 6 | +using System.ComponentModel.DataAnnotations; |
| 7 | +using System.Diagnostics; |
| 8 | +using System.Reflection; |
| 9 | +using System.Text; |
| 10 | +using System.Threading; |
| 11 | +using Xunit; |
| 12 | + |
| 13 | +namespace FreeSql.Tests.Issues |
| 14 | +{ |
| 15 | + public class _576 |
| 16 | + { |
| 17 | + [ExpressionCall] |
| 18 | + public static class _576Extensions |
| 19 | + { |
| 20 | + public static ThreadLocal<ExpressionCallContext> expContext = new ThreadLocal<ExpressionCallContext>(); |
| 21 | + |
| 22 | + /// <summary> |
| 23 | + /// 自定义表达式树函数解析 |
| 24 | + /// </summary> |
| 25 | + /// <param name="that"></param> |
| 26 | + /// <param name="withinCode"></param> |
| 27 | + /// <returns></returns> |
| 28 | + public static string ToNormalWithinCodeGuid([RawValue] this Guid that, string withinCode) |
| 29 | + { |
| 30 | + expContext.Value.Result = $"{expContext.Value.ParsedContent["withinCode"]} || '{that.ToString("N")}'"; |
| 31 | + return null; |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + [Fact] |
| 36 | + public void InsertInto() |
| 37 | + { |
| 38 | + IFreeSql fsql = g.oracle; |
| 39 | + |
| 40 | + |
| 41 | + fsql.Delete<SysRole>().Where("1=1").ExecuteAffrows(); |
| 42 | + var id = Guid.NewGuid().ToString(); |
| 43 | + fsql.Insert(new SysRole { Guid = id, RoleName = "role1", Sort = 1 }).ExecuteAffrows(); |
| 44 | + |
| 45 | + Assert.Equal(1, fsql.Select<SysRole>().Where(a => a.Guid == id).InsertInto("", a => new SysRole |
| 46 | + { |
| 47 | + Guid = "'x123123dasfafd'", |
| 48 | + RoleName = Guid.NewGuid().ToNormalWithinCodeGuid(a.RoleName), |
| 49 | + Sort = a.Sort |
| 50 | + })); |
| 51 | + |
| 52 | + var item = fsql.Select<SysRole>().Where(a => a.Guid == "x123123dasfafd").First(); |
| 53 | + Assert.NotNull(item); |
| 54 | + Assert.True(item.RoleName.StartsWith("role1") && item.RoleName.Length == 37); |
| 55 | + Assert.Equal(item.Sort, 1); |
| 56 | + } |
| 57 | + |
| 58 | + [Table(Name = "issues_576_SysRole")] |
| 59 | + public partial class SysRole |
| 60 | + { |
| 61 | + |
| 62 | + /// <summary> |
| 63 | + /// GUID |
| 64 | + /// </summary> |
| 65 | + [JsonProperty, Column(Name = "GUID", DbType = "VARCHAR2(60 BYTE)", IsPrimary = true)] |
| 66 | + public string Guid { get; set; } |
| 67 | + |
| 68 | + /// <summary> |
| 69 | + /// 角色名称 |
| 70 | + /// </summary> |
| 71 | + [JsonProperty, Column(Name = "ROLE_NAME", DbType = "NVARCHAR2(40)")] |
| 72 | + public string RoleName { get; set; } |
| 73 | + |
| 74 | + /// <summary> |
| 75 | + /// 角色排序 |
| 76 | + /// </summary> |
| 77 | + [JsonProperty, Column(Name = "SORT")] |
| 78 | + public int Sort { get; set; } |
| 79 | + } |
| 80 | + } |
| 81 | +} |
0 commit comments