public IQueryable<TEntity> Find<TEntity>(TEntity obj) where TEntity : class

 BindingFlags.Instance);
Linq 通过反射动态查询对象            
//构造初始的query
Linq 通过反射动态查询对象
            IQueryable<TEntity> query = this.GetTable<TEntity>().AsQueryable<TEntity>();
Linq 通过反射动态查询对象            
//遍历每个property
Linq 通过反射动态查询对象
            foreach (PropertyInfo p in properties)

<
TEntity, bool>>(filter, param);
Linq 通过反射动态查询对象                            query 
= query.Where(pred);
Linq 通过反射动态查询对象                        }

Linq 通过反射动态查询对象                    }

Linq 通过反射动态查询对象                }

Linq 通过反射动态查询对象            }

Linq 通过反射动态查询对象            
return query;
Linq 通过反射动态查询对象        }

 

调用:

Linq 通过反射动态查询对象            Customer c = new Customer();
Linq 通过反射动态查询对象            c.City 
= "London";
Linq 通过反射动态查询对象            c.Phone 
= "23236133";
Linq 通过反射动态查询对象
Linq 通过反射动态查询对象            var q 
= db.Find<Customer>(c).ToList();


相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
  • 2021-11-12
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2021-11-20
  • 2022-12-23
  • 2021-08-13
相关资源
相似解决方案