How to dynamically generate where clause in Linq
Hi allOracle DB: 11 gR 2
Oracle Client: 11.2.0.3.0 (ODP.NET)
Oracle Developer Tools for Visual Studio
VS 2010 (C#)
In a Windows Form, it must query the data based on the values in list dropdown listboxes, which the user selects.
Let's say two combox, one Department and one for salary
Department:
-1 all the
10 Department 1
20 Department 2
30 Department 3
Salary:
-1 all the
1 < 20000
2 20000 to 50000
3 50000 to 100000
4 > 100000
Here is the c# code to query data:
using (var myEDMctx = new HREntities())
{
var LINQrslt = from emp in myEDMctx.EMPLOYEES
Select emp;
}
The default values for the two combox should be everything.
How to write dynamic where clause for this LINQ?
Thanks in advance!
That's what I do.
var query = from c in customers
Select c;
If (where1 > - 1).
Query = query. Where(c.Where1 > where1);
If (where2 > - 1).
Query = query. Where(c.where2 == where2);
to return the query;
Published by: Invincible on July 4, 2012 09:25
Published by: Invincible on July 4, 2012 09:27
Tags: Database
Similar Questions
-
Hallo,
on a view object, I create my view of the criteria customized; I'm going to use it to create a "query with the table panel.
I wish that his beahviour, when I use it to create a "query with the table panel", corresponds to that of "attributes searchable all.
Unfortunately I'm having some trouble in his creation and I would like to see how is made the "object view where Clause" CV "all searchable attributes.
My VO motion is:
Select the username, name, RegisteringDate
I would like to create my VC in a way that is the result "query with table Panel:
UserId | ___ |
Name | ___ |
RegisteringDate of | ___ | to |_________|
For each search field, I set a variable binding (PName, PUserId, PRegisteringDateTo, PRegisteringDateFrom).
Each field must be used in the "query with table Panel" only if it is filled with a value.
You kindly help me?
Thank you very much
F.
The criteria to view all searchable attributes is implied all the attributes of a vo. Each attribute is used unless you specify a value for it. The problem with this IS, is that you can not change it.
However, you can build your own RESUME that works in the same way, but allows you to change certain attributes. To do this, you create a new business card and add each attribute, select the operation you want to test the attribute against (equals, start by,...). You do not bind variables for attributes specify. The framework will add them for you automatically.
The only thing that can not this vc is check varies as you want to do when you check "RegisteringDate." To do this you must use bind variables.
Once you have create this EGG and it makes you drag onto the page you can use it as the "all attributes searchable.
Timo
-
How only include a WHERE clause only when a connection variable has a value?
I use JDeveloper 11 g using business components of the tables. I'm now modify the auto-generated SQL code to include WHERE clauses which depend on the values of bind variables. For example I have something like this:
However, this means that when VariableValue is null SQL would fail and I get an error. Is there a way I can include the WHERE clause (or clause AND according to the position in SQL) only when a bound variable has a value (or a particular value)?SELECT mytable.firstColumn FROM myTable WHERE myTable.secondColumn= :VariableValue
Or use: WHERE NVL(:VariableValue,myTable.secondColumn) = myTable.secondColumn
-
How to define a WHERE clause of the subquery in a bean managed?
Hi people,
is it possible to define the place where clause of a subquery in a bean managed?
For example, it is more SQL charly:
SELECT * FROM
(SELECT Person.Name
OF the person)
To change or add a WHERE clause, I use following code for the 'viewObject: view
String whereClause = "ROWNUM < =: numberOfRows;
viewObject.setWhereClause (whereClause);
viewObject.defineNamedWhereClauseParam ("numberOfRows", null, null);
viewObject.setNamedWhereClauseParam ("numberOfRows", new Number (100));
AttributeList myattr = this.getNamedWhereClauseParams ();
viewObject.setNamedWhereClauseParams (myattr);
For example, this code works well for the first SELECT statement limit the output to the first 100 results. But how do I add a WHERE clause of the subquery in a managed bean? For example, when I want to limit the names of people that begin with the letter "A"?
The query should look like this:
SELECT * FROM
(SELECT Person.Name
OF the person
WHERE Person.Name LIKE 'A %')
Anyone know more?
Thank you!Put a variable binding in your query, something like:
where (: bv is null) or (xxx love: bv)
John
-
How to compare in Where clause
Hello
I need help comparing the value in where clause
There is a table called productivity which has columns as
OBJECT_TYPE, COMPLEXITY, OBJECTIVE
Now my requirement is I have a query like this
SELECT
PRO. PROJECT NAME,
POBJ. OBJECT_NAME,
POBJ.COMPLEXITY,
PRO. EFFORT
Of
PROJECT PRO, PROJECT_OBJECTS POBJ
WHERE
PRO.ID = POBJ.ID
I have to compare data between the effort of columns in the query and target in the table of productivity
SELECT
PRO. PROJECT NAME,
POBJ. OBJECT_NAME,
POBJ. OBJECT_TYPE,
POBJ.COMPLEXITY,
PRO. EFFORT
Of
PROJECT PRO, PROJECT_OBJECTS POBJ
WHERE
PRO.ID = POBJ.PRO_ID
now I change the query to compare
SELECT
PRO. PROJECT NAME,
POBJ. OBJECT_NAME,
POBJ.COMPLEXITY,
-case when
POBJ. OBJECT_TYPE IN (SELECT OBJECT_TYPE OF PRODUCTIVITY) AND
POBJ.COMPLEXITY (SELECT COMPLEXITY OF PRODUCTIVITY)
PRO. EFFORT > (SELECT GOAL OF PRODUCTIVITY WHERE type_objet =? AND
COMPLEXITY =? ) / / here instead of? I have to say
POBJ. OBJECT_TYPE and POBJ.COMPLEXITY
then
10
ON THE OTHER
0
END "Effort."
Of
PROJECT PRO, PROJECT_OBJECTS POBJ
WHERE
PRO.ID = POBJ.PRO_ID
How to specify this POBJ column. OBJECT_TYPE and POBJ.COMPLEXITY in please of? I put please suggest.
Is there a way where we can spend the value of POBJ. OBJECT_TYPE and POBJ.COMPLEXITY to a variable binding and select it in the where clause
Indicate please let me know if this issue is not understood.
Thank you
SudhirSomething like that, maybe?
SELECT PRO.PROJECT_NAME, POBJ.OBJECT_NAME, POBJ.COMPLEXITY, case when PRO.EFFORT > PROD.GOAL then 10 ELSE 0 END "Effort" FROM PROJECTS PRO, PROJECT_OBJECTS POBJ, PRODUCTIVITY PROD WHERE PRO.ID = POBJ.PRO_ID AND POBJ.OBJECT_TYPE = PROD.OBJECT_TYPE (+) AND POBJ.COMPLEXITY = PROD.COMPLEXITY (+)
I did an outer join; don't know if that's what you want - if not, just get rid of the (+) {noformat} {noformat}
-
How to dynamically generate text or all component areas?
Hello
I use Flex4 SDK and Flash Builder with eclipse plugin(trail version) for the development of a flex project.
I have problems to dynamically generate text boxes.
When I click on a link button, I want a text box to display on the screen. I tried a few examples that I found on the internet but without success.
I appreciate your time.
Thank you
Ravi
What error do you get? Maybe try addElement instead of addChild
-
How to dynamically generate columns in conventional reports
Hi all
How to create dynamic columns in classic reports.
I need to create these columns that depends on the difference of the date column start date and end date.
for example: 4 November 2015 start_date and end_date is November 7, 2015
I show the columns Day1, day 2, day 3 and day 4.
and the values of these columns are checkboxes.
Kind regards
Arianne.
Hi ujwala1234,
ujwala1234 wrote:
How to create dynamic columns in classic reports.
I need to create these columns that depends on the difference of the date column start date and end date.
for example: 4 November 2015 start_date and end_date is November 7, 2015
I show the columns Day1, day 2, day 3 and day 4.
and the values of these columns are checkboxes.
The old packed timesheet application has the tip for how to display the day of the week selected by the user in the form of columns in the tabular presentation.
Reference: old packages of timesheet Application
That's how I'd do:
- Select the range of dates populate the days between the date columns range in a collection of the APEX.
- Display the columns as editable using the APEX_ITEM API.
NOTE: Application of time sheets there was select list for weeks, so always the number of dynamic columns would be 7 + column code time.
Also, the maximum number of modifiable columns, you can use on your page APEX is 50.
Kind regards
Kiran
-
I have a filterable table, and when I have a key value in a filter (on a column of varchar/string) I see that the product where the clause contains
AS UPPER (: vc_temp_1 |) '%')
This is the default behavior that is expected to add on a wildcard '%' at the end?
Thank you.
Version 12.1.3.0.0
Yes. See http://docs.oracle.com/cd/E23943_01/web.1111/b31974/web_search_bc.htm#ADFFD1757 for more information.
You can create a view that uses equals instead of "begins by" If you like and use it to filter criteria.
Timo
-
How to dynamically generate data to be consumed by a LineGraph?
Hello
I am trying to build a LineGraph with the data I have on a collection called ArrayCollection pebw. I've noticed that the ArrayCollections used as dataProviders for a LineGraph usually go as follows (for example):
private var expensesAC: ArrayCollection collection = new ArrayCollection ([] collection
{Month: "Jan", profit: 2000, expenses: 1500, amount: 450},
{Month: benefit "Feb": 1000, expenses: 200, amount: 600},
{Month: "Mar", profit: 1500, expenses: 500, amount: 300},
{Month: "ARP", profit: 1800, expenses: 1200, amount: 900},
([{Month: "May", profit: 2400, expenses: 575, quantity: 500}]) ;
who provides the data and labels. How can I activate my pewb, who has data such that week (which would be the horizontal axis), TotalEnergySpent and devices (which would have a line in the chart for each device) in a table like expensesAC?
OK just
You need browse these data everywhere where its come and then add it to the collection arrayCollection objects;
In a loop you would say;
[Bindable]
var pewb:ArrayCollection = new ArrayCollection()
for (var i: int = 0; i
Whenever you browse a new object is created and added to the arraycollection collection
var obj:Object = new Object()
obj. Week = "Jan"; share these values to the data source values.
obj. TotalEnergy = 2000;
obj. Devices = 100;
pewb.addItem (obj);
}
The arraycollection collection would be a collection of objects that the chart can then identify the fields that you want to use.
OK or not?
-
Need help with dynamic where clause.
Hello world. I'm kind of a novice with PL/SQL, so please be patient with me. I am building a web application using Weblogic Oracle 11 g and Oracle database.
To make a long story short, I need to generate the complex dynamic WHERE clause. I don't know what will be the name of the column or the operator of comparison or the value will be until the moment of execution.
I'm not 100% certain, but I think I need to use dynamic SQL statements. Unless there is a better way to do it.
I'm sure that using dynamic SQL opens me up to SQL injection attacks if I use simple string concatenation. I would like to use bind variable if possible.
In any case, it seems like trying to build a dynamic where clause does not seem to work as I want it would be...
bv1 := 'colA = 5 and colB >= 9'; query_str := 'SELECT * FROM view WHERE :bv1'; OPEN CUR FOR query_str USING bv1;
The code above pours out when I try to run it.
Is there a way to build dynamic where the provisions without the use of concatenation of simple string that leaves me open to attacks by SQL injection?
Thank you
Hello. I have read briefly upward on things, you suggested, but it seems a bit abstract for me since I was a novice.
Can you give us an explanation or an example of how to use it to accomplish what I need to do?
Do ypu really plan create a query with a WHERE clause that contains a predicate for all possible columns?
Variable bind offer performance when the same query is executed several times with different values for bind variables.
Select * from emp where empno =: v_empno
After the first run Oracle will always be this query in the library cache. The next running can use the version of the cache even if the bind value is different.
Select * from emp where empno =: v_empno;
Select * from emp where ename =: v_ename;
Select * from emp where sal =: v_sal;
Each one is a DIFFERENT query. Yes - each of them uses a variable binding, but queries are different.
So, if your username select EMPNO, an '=', and a value from the first query can be executed. But the next time that the user can select the ENAME column so that 'stored' first request may not be used given that the query does not match.
The third time your user selects SAL so none of the first two queries can be used in the library cache. The use of bind variables gives performance during the SAME QUERY is used multiple times with DIFFERENT values for the variable binding. Oracle is not to analyze the hard query everything simply because the VALUE is different.
So bind variables do not help you if most of the queries were completely DIFFERENT sets of predicates. And SYS_CONTEXT will not help either since that simply provides a way to define binds the values of the variables.
Just for the simple example above, there are at least SIX possible combinations of columns that could choose your user name: empno, ename, sal, empno ename, empno & sal, ename & sal
-
Hallo,
I have a request based on VO.
The query contains a where clause clause and a bindi variable.
In a managed bean I would like to access the iterator of VO setting the value of the bind variable and read the result.
I found this code it is good start, but I do not know how to set the variable binding.
BindingContext bctx = BindingContext.getCurrent(); BindingContainer bindings = bctx.getCurrentBindingsEntry(); DCIteratorBinding iter = (DCIteratorBinding ) bindings.get("MyVO1Iterator"); iter.execute();
You kindly help me?
Also, I would like to know if it is generally advisable to use VO directly in controlled beans or whether it would be best to create in the AppModuleImpl methods that do this and return the result.
In my case for example of the VO will return max 1 plug so I'm in doubt, if the creation of a method in the AM that returns a custom class, which attributes contain values of the line of VO.
Sorry if these questions may seem artificial, but I am a beginner, I have many doubts and so I would be happy to receive some tips regarding best practices.
Thank you
Federico
You can use:
iter.getViewObject().setNamedWhereClauseParam("yourBindVar", value);
Note that this approach is used if you have bind variable in the where clause.
To set variables bind to ViewCriteria, you must use VarableValueManager.
This post may be useful for you: binary: how to set the Bind variable values at run time?
Also, I would like to know if it is generally advisable to use VO directly in controlled beans or whether it would be best to create in the AppModuleImpl methods that do this and return the result.
You must set "use VO directly.
For example, from the point of architecture, is probably best to use the method in the model project which will set the bind variable and execute the query.
Or you can use the ExecuteWithParams operation in your the view layer.
In my case for example of the VO will return max 1 plug so I'm in doubt, if the creation of a method in the AM that returns a custom class, which attributes contain values of the line of VO.
Not to complicate your life
All VO lines are represented as ViewRowImpl class if you already have "custom class".
Finally, you can generate your own ViewRowImpl class if it is necessary for this.
Dario
-
Dear all,
I have a problem in the dynamic where clause in the OPS.
I have a VO query as below:
SELECT desc, ccuid, containid, XXXTMP conainline
I'll put whereclause as below:
VO.setwhereclause ("containid '101' =" + "order by containline desc")
so the question is request forms as below:
SELECT desc, ccuid, containid, XXXTMP conainline
(where containid = '101' containline desc order) -query gives question, adding the command from the inside of the caliper
Ideally, order by clause should come outside of the Stirrup.
so, how do I do order by clause order side where clasue or how do I remove the stand before the where clause. So I need the query as below:
SELECT desc, ccuid, containid, XXXTMP conainline
(where containid = '101' containline desc order)
SELECT desc, ccuid, containid, conainline from XXXTMP where containid = '101' containline desc order
or
SELECT desc, ccuid, containid, XXXTMP conainline
(where containid = '101') order by containline desc
Thank you
Hello
Solution 1-
You can use "setOrderByClause (containline desc);" so that it will get out of Where clause.
Solution 2-
Instead of dynamically add Whereclause, you can bind the variable as below-
Query in VO-
SELECT desc, ccuid, containid, conainline from XXXTMP where containid =: 1 containline desc order
In VOImpl-
public void initQuery (String variable)
{
clearCache();
setMaxFetchSize(-1);
setWhereClause (null);
setWhereClauseParams (null);
setWhereClauseParam (0, variable);
executeQuery();
}
Vall of this VOImpl method, and pass the variable value. It will work according to your requirement.
Thank you
Kone
-
Problem with dynamic setting where the clause OFA
Hi all
I have a view object with the following query:
SELECT rownum LINENUM,
B.line_id LINE_ID,
B.INVENTORY_ITEM_ID INVITMID,
B.QUANTITY_DELIVERED PICKQTY
MTL_TXN_REQUEST_HEADERS a,.
MTL_TXN_REQUEST_LINES B
WHERE A.HEADER_ID = B.HEADER_ID
AND A.MOVE_ORDER_TYPE = 2
AND "on" =: 1
AND B.TO_SUBINVENTORY_CODE = NVL(:4,B.TO_SUBINVENTORY_CODE)
AND A.request_number = NVL(:5,A.REQUEST_NUMBER)
UNION ALL
SELECT rownum LINENUM,
a.wip_entity_id LINE_ID,
a.INVENTORY_ITEM_ID INVITMID,
a.QUANTITY_ISSUED PICKQTY
WIP_REQUIREMENT_OPERATIONS has
eam_work_orders_v b
WHERE a.wip_entity_id = b.wip_entity_id
AND "on" =: 2
AND a.ATTRIBUTE2 = NVL(:4,a.ATTRIBUTE2)
and b.wip_entity_name = NVL(:6,b.wip_entity_name)
I need to dynamically pass a condition to my where clause that I can manage it by setting two binding settings in the query of vo and can pass it on but the problem is the connection variable contains a string like 1311,13112,14445 that I need to spend for a domain like B.line_id in the first query and b.wip_entity_id in the second query , so when I'm passing the string as a value it works fine, but it gives for value separetd by comma prob.
so I tried passing dynamic where clause, but there is every time that the execution of the first clause only how can I dynamically pass both queries.
vo.setWhereClause ("LINE_ID in" + wherclause);
Please help me
Thnaks
Deb
Hello
Actually I'm passing the parameter to the basic page popup, so in page popup page and the base, I was using the VO even to run then, probably due to that he was running again for all data, so for the basic page I created a new VO and tried to pass the parameter like when clause for questioning now it runs very well Thank you for all your help
-
Construction of a dynamic Where clause:
Hi experts,
In my environment real time in the java code for a statement select query they they add dynamically to the place where clause and retrieve the data using hybernet. I want to do it in PL/SQ
(1) is it possible?
(2) how can I do this
(3) can provide you with the example of document or for example for this one. Please help me>
In my environment real time in the java code for a statement select query they they add dynamically to the place where clause and retrieve the data using hybernet. I want to do it in PL/SQ(1) is it possible?
>
Non - Oracle can not recover the data using hybernet.
>
(2) how can I do this
>
You can't - see response to #1 above
>
(3) can provide you with the example of document or for example for this one. Please help me
>
Not until give you an example of a document or an example of what you speak again. -
Very Urgent: Setting dynamic where clause for Popup list VO
Hello world
It is a very urgent requirement please help as soon as possible.
I have a custom page in iSupplier. I created two supplier site, number of PO fields.
Site of beg - choice of Message and PO number - Message LOV of entry
I have a named VO under xxisupplier.oracle.apps.pos.home.poplist.server for site begging and xxisupplier.oracle.apps.pos.home.lov.server for PO number.
I have joined these two VO AM homepage.
Now the question is
1. I want to restrict these VO vendor_id-based so I'll put dynamically where clause for these two VO of in my CO
VO SITE PROVIDER QUERY
SELECT POVs.vendor_site_code site, pov.vendor_id
OF po_vendors pov, povs po_vendor_sites_all
WHERE pov.vendor_id = povs.vendor_id
AND TRUNC (povs.inactive_date) IS NULL
PO NUMBER LOV QUERY VO
SELECT DISTINCT ai.invoice_num, ai.vendor_id, ai.invoice_date, poh.segment1
AI ap_invoices_all,.
help ap_invoice_distributions_all,
po_headers_all poh,
po_distributions_all pda,
Al ap_lookup_codes
WHERE aid.po_distribution_id = pda.po_distribution_id
AND ai.invoice_id = aid.invoice_id
AND poh.po_header_id = pda.po_header_id
AND ai.invoice_type_lookup_code = al.lookup_code
AND al.lookup_type = 'INVOICE TYPE'
I am creating where cluase as below in CO
If (vendor_id1! = null)
{
System.out.println ("vendor_id:" + vendor_id1);
OAViewObjectImpl vo = (OAViewObjectImpl) am.findViewObject ("PO_LOV_VO");
if(vo!=null)
{
vo.clearCache ();
VO. Reset();
System.out.println ("inside IN. VO:" + vendor_id1);
vo.setWhereClause (null);
vo.setWhereClause ("vendor_id =: 1");
vo.setWhereClauseParams (null);
vo.setWhereClauseParam(0,vendor_id1);
vo.setOrderByClause ("invoice_date DESC");
String INVQRY = vo.getQuery ();
System.out.println ("INVQRY:" + INVQRY);
vo.executeQuery ();
VO. First();
System.out.println ("after the query appear" + vo.getRowCount ());
}
OAViewObjectImpl sitevo1 = (OAViewObjectImpl) am.findViewObject ("SUPPLIER_SITE_VO1");
if(sitevo1!=null)
{
sitevo1.clearcache ();
sitevo1. Reset();
System.out.println ("Interior site:" + vendor_id1);
sitevo1.setWhereClause (null);
sitevo1.setWhereClause ("vendor_id =: 1");
sitevo1.setWhereClauseParams (null);
sitevo1.setWhereClauseParam(0,vendor_id1);
String SITEQRY = sitevo1.getQuery ();
System.out.println ("SITEQRY:" + SITEQRY);
sitevo1. ExecuteQuery();
sitevo1. First();
System.out.println ("after the query appear" + sitevo1.getRowCount ());
}
Here he works for the purchase order number but the where cluase does not work for Supplier Site. Please help as soon as possible.
2 and also if supplier site to return multiple values then this field should show as messagechoice. If it returns a single value, then it should be the style text message
How can I achieve this.
Thank you
CSKTry
vo.setWhereClause ("IN vendor_id (" + vendor_id_qry + ")" ");
vendor_id_qry is the query that retrieves the list of provider IDS. You don't need to put the vendor column id as whereClauseParam unless you want to have IN the clause in your query of VO and pass the list as 1,2,3 values to the parameter.
Thank you
Shree
Maybe you are looking for
-
Satellite U840W - disc cannot be displayed in disk part operating system does not start
Yesterday I tried to boot my laptop Toshiba Satellite U840W (PSU5XA-001006) and it came with no bootable device - please reboot When I try to view the disc in the part of the disk, it cannot see that the USB key that I use to try to reinstall Win 8.
-
Portege Z930 there a noisy fan, buzzing like the Z830?
Someone at - it the Z930? I wanted to know if the fan hums like the Z830. Is it quiet so you will hear only air or did you hear a buzzing sound when the fan is used? Thank you
-
Re: Satellite M70-131 - RAM and CPU upgrade
Hello, I have 2 questions:1 is it possible to install more then 2048 MB RAM in M70 - 131. If someone tried this?2. is it possible to install the new processor of M70 - 131? Now, i've got Pentium M (750) 1, 86GHz (Dothan, 533 MHz). Can I install for e
-
Satellite M30: Wireless light does not come
My wireless on my laptop light is not.I switch wireless enabled but the light does not come and my router is turned on. Also, I can't check the local networks.Could someone help me identify this problem?
-
Touch (buttons) does not not on HP pavilion DV7
Hello I'm new here. I just bought a HP pavilion DV7 laptop 1285dx of entertainment 5 days ago, and the touch buttons for volume, mute, play, pause, before, back buttons and WiFi stop working. They never really seem to work perfectly. kind of hit and