标签: dynamicquery

如何在动态SQL查询中设置表名?

我想在动态SQL查询中设置表名.我成功尝试参数如下:

/* Using sp_executesql */
/* Build and Execute a Transact-SQL String with a single parameter 
value Using sp_executesql Command */

/* Variable Declaration */
DECLARE @EmpID AS SMALLINT
DECLARE @SQLQuery AS NVARCHAR(500)
DECLARE @ParameterDefinition AS NVARCHAR(100)
/* set the parameter value */
SET @EmpID = 1001
/* Build Transact-SQL String by including the parameter */
SET @SQLQuery = 'SELECT * FROM tblEmployees WHERE EmployeeID = @EmpID' 
/* Specify Parameter Format */
SET @ParameterDefinition =  '@EmpID SMALLINT'
/* Execute Transact-SQL …
Run Code Online (Sandbox Code Playgroud)

sql sql-server parameters sql-server-2008 dynamicquery

21
推荐指数
3
解决办法
9万
查看次数

动态LINQ中的条件

我有一个场景,我必须在LINQ中使用动态where条件.

我想要这样的东西:

public void test(bool flag)
{
   from e in employee
   where e.Field<string>("EmployeeName") == "Jhom"
   If (flag == true)
   {
       e.Field<string>("EmployeeDepartment") == "IT"
   }
   select e.Field<string>("EmployeeID")
}
Run Code Online (Sandbox Code Playgroud)

我知道我们不能在Linq查询的中间使用'If'但是这个解决方案是什么?

请帮忙...

c# linq linq-to-sql dynamicquery

11
推荐指数
2
解决办法
2万
查看次数

Spring Data动态查询

我正在尝试使用spring数据设置动态查询,基本上我有一堆具有一系列特征的数组,我需要根据这些特性组装查询,几乎就像"WHERE特征= A AND特征= B AND特征= C"但特征量可能不同.

我注意到我可以使用@Query注释但是可以将@Query的结果分页吗?

有没有其他方法可以实现这一目标?

Page<Recipe> findDistinctByNameContainingAndOrganizationAndCharacteristicsInOrIngredientsContainingAndOrganizationAndCharacteristicsInOrDescriptionContainingAndOrganizationAndCharacteristicsInAllIgnoreCase(
        String name, Organization organization1, List<Characteristic> characteristic1,
        String ingredients, Organization organization2, List<Characteristic> characteristic2,
        String description, Organization organization3, List<Characteristic> characteristic3,
        Pageable pageable);
Run Code Online (Sandbox Code Playgroud)

java spring dynamicquery spring-data

11
推荐指数
1
解决办法
2万
查看次数

如何初始化Spring Data JPA的规范?

我有一个使用过滤器进行搜索的方法,所以我使用Specification来构建动态查询:

public Page<Foo> searchFoo(@NotNull Foo probe, @NotNull Pageable pageable) {

        Specification<Foo> spec = Specification.where(null);  // is this ok?

        if(probe.getName() != null) {
            spec.and(FooSpecs.containsName(probe.getName()));
        }
        if(probe.getState() != null) {
            spec.and(FooSpecs.hasState(probe.getState()));
        }
        //and so on...

        return fooRepo.findAll(spec, pageable);
}
Run Code Online (Sandbox Code Playgroud)

有可能没有指定过滤器,所以我会列出所有没有过滤的东西.那么考虑到这一点,我应该如何初始化spec?现在,上面的代码不起作用,因为它总是返回相同的结果:表的所有寄存器,没有过滤已经做过and操作.

FooSpecs:

public class PrescriptionSpecs {

    public static Specification<Prescription> containsCode(String code) {
        return (root, criteriaQuery, criteriaBuilder) ->
            criteriaBuilder.like(root.get(Prescription_.code), "%" + code + "%");
    }

    // some methods matching objects...
    public static Specification<Prescription> hasContractor(Contractor contractor) {
        return (root, …
Run Code Online (Sandbox Code Playgroud)

java dynamicquery spring-data-jpa

10
推荐指数
1
解决办法
2563
查看次数

如何将此Linq SQL编写为动态查询(使用字符串)?

根据需要跳到"特定问题".一些背景:

场景: 我有一组产品,其中包含一个填充了DDL的"向下钻取"过滤器(查询对象).每个渐进式DDL选择将进一步限制产品列表以及DDL的剩余选项.例如,从工具中选择锤子会限制产品尺寸仅显示锤子尺寸.

当前设置:我创建了一个查询对象,将其发送到存储库,并将每个选项提供给SQL"表值函数",其中空值表示"获取所有产品".

我认为这是一个很好的努力,但远非DDD可以接受.我想避免SQL中的任何"编程",希望用存储库做所有事情.对此主题的评论将不胜感激.

具体问题:

我如何将此查询重写为动态查询?像101 Linq Examples这样的链接会很棒,但是有一个动态查询范围.我真的想将这个方法传递给引号""中的字段,我想要一个选项列表以及有多少产品具有该选项.

from   p in db.Products
group  p by p.ProductSize into g
select new Category { 
       PropertyType = g.Key,
       Count = g.Count() }
Run Code Online (Sandbox Code Playgroud)

每个DDL选项都有"选择(21)",其中(21)是具有该属性的产品数量.选择一个选项后,所有其他剩余的DDL将使用剩余的选项和计数进行更新.

编辑:附加说明:

.OrderBy("it.City") // "it" refers to the entire record
.GroupBy("City", "new(City)") // This produces a unique list of City
.Select("it.Count()") //This gives a list of counts... getting closer
.Select("key") // Selects a list of unique City
.Select("new (key, count() as string)") // +1 to …
Run Code Online (Sandbox Code Playgroud)

c# linq repository linq-to-sql dynamicquery

6
推荐指数
1
解决办法
4050
查看次数

如何将Linq动态查询结果转换为自定义类?

通常,我这样做:

var a = from   p in db.Products
        where  p.ProductType == "Tee Shirt"
        group  p by p.ProductColor into g
        select new Category { 
               PropertyType = g.Key,
               Count = g.Count() }
Run Code Online (Sandbox Code Playgroud)

但我有这样的代码:

var a = Products
        .Where("ProductType == @0", "Tee Shirt")
        .GroupBy("ProductColor", "it")
        .Select("new ( Key, it.Count() as int )");
Run Code Online (Sandbox Code Playgroud)

我可以改变什么语法来产生相同的结果,即如何从第二个Linq语句中对Category进行投影?

我知道在这两者是一样的,代表整个表的记录,那我拉整条记录中只是做一个计数.我也需要解决这个问题. 编辑:Marcelo Cantos指出Linq非常聪明,不会提取不必要的数据.谢谢!

c# linq dynamicquery

5
推荐指数
1
解决办法
3072
查看次数

让所有用户在Liferay中获得角色

我是Liferay开发的新手,所以请随时指出我是否完全采用了错误的方法.

我正在尝试获取某个组内所有用户的DynamicQuery对象(我将使用此对象进一步过滤我将针对留言板执行的另一个查询).该User接口似乎有一个roleIds,我可能能够使用的财产,因为我已经知道roleId我很感兴趣,但我无法找到查询是否正确的方法roleIds 包含一定的价值.

关于我想做什么的任何想法?

PS:我想有确切的SQL查询,我可以直接问,但我宁愿使用Liferay的自己的连接池,而无需做一些奇怪的ext工程啄.

java liferay dynamicquery liferay-6

5
推荐指数
2
解决办法
1万
查看次数

如何从字段列表创建动态查询?

我正在尝试使用PHP和MySQL构建动态查询.

我所做的是创建一个表(即.field_relations)这个字段有5列

  1. field_name(字段名称"ie.count_id,account_name ....")
  2. display_label(字段应如何移位到使用"ie.帐户ID,名称")
  3. table_name(此字段属于"即帐户"的表)
  4. related_to(与不同表的字段关系"如果有的话."默认值为NULL)
  5. related_to_field(指向"if any"的字段.默认值为NULL)

这是一个示例数据 field_name display_label table_name related_to related_to_field account_id Account ID accounts NULL NULL account_name Name accounts NULL NULL first_name First Name contacts NULL NULL last_name Last Name contacts NULL NULL contact_id Contact ID contacts NULL NULL account_id Account ID contacts accounts account_id task_id Task ID tasks NULL NULL subject Subject tasks NULL NULL owner_id Assigned To contacts contacts contact_id daily_sales Sales transactions accounts account_id sold_on Sold …

php mysql dynamicquery

5
推荐指数
1
解决办法
1642
查看次数

如何在mongodb查询中传递一个空的php变量

我想创建一个动态mongodb查询,如果条件为真,则插入其聚合的每个部分,否则不注入该部分.

例如,我想检查时间是否在凌晨1点到8点之间.如果是,则将定义的数组传递给mongodb查询,否则不传递任何内容.

if ($this->Not_in_1_8 == true) {
    $this->N_IN_1_8 = array('dont_show_between_1_n_8' => array('$ne' => true));
}else {
    $this->N_IN_1_8 = null;
}
$MidnightCheck = $this->N_IN_1_8;
$this->campaign = Bcamp::raw(function ($collection) use ($seat_category_list, $banner_size, $seat_filter_list, $gold_network, $MidnightCheck) {
    return $collection->aggregate([
        [
            '$match' => [
                '$and' => [
                    ["targets.cats" => [
                        '$in' => $seat_category_list
                        ]
                    ],
                    ['banners.' . $banner_size => [
                        '$exists' => true
                        ]
                    ],
                    ['href' => [
                        '$nin' => $seat_filter_list
                        ]
                    ],
                    ['targets.gold_network' => [
                        '$eq' => $gold_network
                        ]
                    ],
                    ['status' => [ …
Run Code Online (Sandbox Code Playgroud)

php database mongodb dynamicquery is-empty

5
推荐指数
1
解决办法
264
查看次数

用于创建具有内部Collection的谓词的动态查询

我正在为我的MVC EF应用程序创建搜索功能.我正在使用动态查询创建它.并遵循此方法https://www.codeproject.com/Articles/493917/Dynamic-Querying-with-LINQ-to-Entities-and-Express

它用于创建实体的谓词boolstring字段.我的应用程序中的主要实体是Applicant

EDMX Applicant正在关注

     public partial class Applicant
    {

      public Applicant()
       {
         this.ApplicantEducations = new HashSet<ApplicantEducation>();
         this.ApplicantSkills = new HashSet<ApplicantSkill>();
         this.Applications = new HashSet<Application>();
         this.Experiences = new HashSet<Experience>();
        }

    public int Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public byte[] CV_Upload1 { get; set; }
    public string CV_Upload2 { get; set; }
    public string email { get; set; …
Run Code Online (Sandbox Code Playgroud)

.net c# linq dynamicquery entity-framework-6

5
推荐指数
0
解决办法
1349
查看次数