1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
static IEnumerable<MethodInfo> GetExtensionMethods(Assembly assembly, Type extendedType)
 {
     var query = from type in assembly.GetTypes()
                 where !type.IsGenericType && !type.IsNested
                 from method in type.GetMethods(BindingFlags.Static
                     | BindingFlags.Public | BindingFlags.NonPublic)
                 where method.IsDefined(typeof(System.Runtime.CompilerServices.ExtensionAttribute), false)
                 where method.GetParameters()[0].ParameterType == extendedType
                 select method;
     return query;
 } public static Expression<Func<T, bool>>  IsGreaterThan<T>( string propertyName, byte[] values) where T : class
 {
     if(values == null || !values.Any())
     {
         throw new ArgumentException("The values collection must not be null or empty.", nameof(values));
     }
 
     // 获取泛型类型 T 的 PropertyInfo 
     var propertyInfo = typeof(T).GetProperty(propertyName);
     if (propertyInfo == null)
     {
         throw new ArgumentException($"Property '{propertyName}' not found on type '{typeof(T).Name}'.", nameof(propertyName));
     }
 
     // 创建参数表达式,表示 T 类型的实例 
     var parameter = Expression.Parameter(typeof(T), "entity");
 
     // 创建属性访问表达式,表示访问 T 类型的 propertyName 属性 
     var propertyAccess = Expression.Property(parameter, propertyInfo);
 
     // 将 values 集合转换为 Expression 常量数组 
     var constantExpression = Expression.NewArrayInit(typeof(byte), values.Select(v => (Expression)Expression.Constant(v, typeof(byte))));
 
     // 创建 Contains 方法调用表达式,注意这里我们假设 TValue 是可比较的,并且支持 Contains 方法 
     // 实际上,在 LINQ to Entities 中,我们需要使用 DbSet.Contains 或者手动映射到 SQL 的 IN 子句 
     // 这里我们使用一个假设的 Contains 方法作为演示,实际中需要替换为合适的实现  \\
     Assembly assembly = Assembly.GetExecutingAssembly();
     var dd = typeof(byte[]).GetMethods().ToList();
    
     var containsMethod = GetExtensionMethods(assembly, typeof(byte[]))
 
         .Single(m => m.Name == "Compare" && m.GetParameters().Length == 2)
         ;
 
     var containsExpression = Expression.Call(
         null, // 对于静态方法,第一个参数是 null 
         containsMethod,
         constantExpression, // 数组参数 
         propertyAccess // 要检查是否包含的属性值 
     );
 
     // 注意:上面的 ContainsExpression 在 EF Core 中不会直接工作,因为它引用的是 Enumerable.Contains 
     // 而不是 EF Core 能够转换为 SQL IN 子句的表达式。因此,在实际应用中,你可能需要手动构建 Expression.Call 
     // 调用数据库上下文中的某个 DbSet 的 Contains 方法,或者使用其他方法将表达式转换为 SQL IN 子句。 
 
     // 创建一个 lambda 表达式 
     var lambda = Expression.Lambda<Func<T, int>>(containsExpression, parameter);
 
 
     var parameter2 = lambda.Parameters[0]; // 获取原始lambda的参数 
     var body = Expression.LessThan(lambda.Body, Expression.Constant(0)); // 创建新的body,检查是否大于10 
     Expression<Func<T, bool>> newLambda = Expression.Lambda<Func<T, bool>>(body, parameter2);
     // 返回 lambda 表达式,但请注意,它可能不会在 EF Core 中直接工作,除非你进一步处理它 
     return newLambda;
 }

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public static Expression<Func<T, bool>> BuildInExpression<T, TValue>(string propertyName, IEnumerable<TValue> values)
  {
      if (values == null || !values.Any())
      {
          throw new ArgumentException("The values collection must not be null or empty.", nameof(values));
      }
 
      // 获取泛型类型 T 的 PropertyInfo 
      var propertyInfo = typeof(T).GetProperty(propertyName);
      if (propertyInfo == null)
      {
          throw new ArgumentException($"Property '{propertyName}' not found on type '{typeof(T).Name}'.", nameof(propertyName));
      }
 
      // 创建参数表达式,表示 T 类型的实例 
      var parameter = Expression.Parameter(typeof(T), "entity");
 
      // 创建属性访问表达式,表示访问 T 类型的 propertyName 属性 
      var propertyAccess = Expression.Property(parameter, propertyInfo);
 
      // 将 values 集合转换为 Expression 常量数组 
      var constantExpression = Expression.NewArrayInit(typeof(TValue), values.Select(v => (Expression)Expression.Constant(v, typeof(TValue))));
 
      // 创建 Contains 方法调用表达式,注意这里我们假设 TValue 是可比较的,并且支持 Contains 方法 
      // 实际上,在 LINQ to Entities 中,我们需要使用 DbSet.Contains 或者手动映射到 SQL 的 IN 子句 
      // 这里我们使用一个假设的 Contains 方法作为演示,实际中需要替换为合适的实现 
      var containsMethod = typeof(Enumerable).GetMethods()
          .Single(m => m.Name == "Contains" && m.GetParameters().Length == 2)
          .MakeGenericMethod(typeof(TValue));
 
      var containsExpression = Expression.Call(
          null, // 对于静态方法,第一个参数是 null 
          containsMethod,
          constantExpression, // 数组参数 
          propertyAccess // 要检查是否包含的属性值 
      );
 
      // 注意:上面的 ContainsExpression 在 EF Core 中不会直接工作,因为它引用的是 Enumerable.Contains 
      // 而不是 EF Core 能够转换为 SQL IN 子句的表达式。因此,在实际应用中,你可能需要手动构建 Expression.Call 
      // 调用数据库上下文中的某个 DbSet 的 Contains 方法,或者使用其他方法将表达式转换为 SQL IN 子句。 
 
      // 创建一个 lambda 表达式 
      var lambda = Expression.Lambda<Func<T, bool>>(containsExpression, parameter);
 
      // 返回 lambda 表达式,但请注意,它可能不会在 EF Core 中直接工作,除非你进一步处理它 
      return lambda;
  }

  

posted @ 2024-06-25 23:25 zx132797 阅读(10) 评论(0) 推荐(0) 编辑
该文被密码保护。 阅读全文
posted @ 2023-09-07 11:24 zx132797 阅读(1) 评论(0) 推荐(0) 编辑
摘要: SELECT CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server, msdb.dbo.backupset.database_name, msdb.dbo.backupset.backup_start_date, msdb.dbo.ba 阅读全文
posted @ 2023-06-19 23:25 zx132797 阅读(195) 评论(0) 推荐(0) 编辑
摘要: https://github.com/ReubenBond/DeepCopy 阅读全文
posted @ 2022-02-20 00:29 zx132797 阅读(9) 评论(0) 推荐(0) 编辑
该文被密码保护。 阅读全文
posted @ 2022-01-09 23:09 zx132797 阅读(4) 评论(0) 推荐(0) 编辑
摘要: sql SqlServer 不可复读和幻读的定义,是根据自己的理解写出来的,不是真正的定义,哈哈! 一、定义 1.脏读 事务A向表中插入了一条数据,此时事务A还没有提交,此时查询语句能把这条数据查询出来,这种现现象称为脏读;脏读比较好理解 2.不可重复读 一个事务A第一次读取的结果之后, 另外一个事 阅读全文
posted @ 2017-07-28 15:47 zx132797 阅读(2673) 评论(0) 推荐(0) 编辑
摘要: jQuery(function ($) { // 备份jquery的ajax方法 var _ajax = $.ajax; // 重写ajax方法,先判断登录在执行success函数 $.ajax = function (opt) { var _success = opt && opt.success || function (a, b) { }; var _opt = $.extend(op... 阅读全文
posted @ 2016-06-03 10:36 zx132797 阅读(369) 评论(0) 推荐(0) 编辑
摘要: 1.创建(安装)windows服务:输入sccreatetest binPath= E:\Test\test.exe 回车。注意:“binPath=”后面必须加一个空格。 这时候就可以在计算机>>服务 中自己新建的 test 服务2.卸载服务 sc deletetest3.语法:sccreate|delete|config服务名[参数] 阅读全文
posted @ 2014-03-09 22:23 zx132797 阅读(168) 评论(0) 推荐(0) 编辑
摘要: IIS6注册HttpModule IIS7注册HttpModule 阅读全文
posted @ 2013-09-15 17:27 zx132797 阅读(340) 评论(0) 推荐(0) 编辑
摘要: var tt = document.getElementById(id); var ttop = tt.offsetTop;//绝对位置 left 的距离 var thei = tt.clientHeight; var tleft = tt.offsetLeft;//绝对位置距离页面的 top的高 while (tt = tt.offsetParent) { ttop += tt.offsetTop; tleft += tt.offsetLeft; }var treebg=document.getElementById("test"); treebg.style.top = 阅读全文
posted @ 2013-03-04 16:31 zx132797 阅读(573) 评论(0) 推荐(0) 编辑
点击右上角即可分享
微信分享提示