dynamicquery

Dynamic where condition in LINQ

萝らか妹 提交于 2019-11-30 09:04:53
I have a scenario where I have to use a dynamic where condition in LINQ. I want something like this: 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") } I know we can't use the 'If' in the middle of the Linq query but what is the solution for this? Please help... So, if flag is false you need all Jhoms, and if flag is true you need only the Jhoms in the IT department This condition !flag || (e.Field<string>("EmployeeDepartment") == "IT"

Dynamic where condition in LINQ

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 12:43:43
问题 I have a scenario where I have to use a dynamic where condition in LINQ. I want something like this: 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") } I know we can't use the 'If' in the middle of the Linq query but what is the solution for this? Please help... 回答1: So, if flag is false you need all Jhoms, and if flag is true you need only

Spring Data MongoDB Repository - JPA Specifications like

时光总嘲笑我的痴心妄想 提交于 2019-11-29 11:30:57
Is there something like JPA Specifications for Spring Data MongoDB Repositories? If not, how can I make dynamic queries with repositories? A classic scenario could be a search form with optional fields that the user will fill. I found myself a way. The trick can be done using QueryDSL , in the following way: First, add the QueryDSL dependencies: <dependency> <groupId>com.mysema.querydsl</groupId> <artifactId>querydsl-mongodb</artifactId> <version>${querydsl-mongo.version}</version> </dependency> <dependency> <groupId>com.mysema.querydsl</groupId> <artifactId>querydsl-apt</artifactId> <version>

How to set table name in dynamic SQL query?

怎甘沉沦 提交于 2019-11-26 13:45:00
I want to set table name in a dynamic SQL query. I tried successfully for parameter as following: /* 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 = '

How to set table name in dynamic SQL query?

守給你的承諾、 提交于 2019-11-26 05:54:23
问题 I want to set table name in a dynamic SQL query. I tried successfully for parameter as following: /* 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 *