ExpressionQueryImpl<TElement>.ToString() doesn't update SQL text when parameter's values changes
See original GitHub issueHello,
when we build queries with linq2db we get an ExpressionQueryImpl<TElement>
object that implements IQueryable<T>
interface.
For example:
...
DataConnection.DefaultSettings = new MySettings();
Configuration.Sql.GenerateFinalAliases = true;
using var db = new WipDB("Wip");
var wipCte = new WipCte(db);
var ncCodeBo = "NCCodeBO:8110,SETUP_OSCILLOSCO";
var result = from item in wipCte.AllowedNcCode() where item.NcCodeBo == ncCodeBo select item;
var sql = result.ToString();
Console.WriteLine(sql);
..
Output:
-- Wip Oracle.Managed Oracle
DECLARE @ncCodeBo_1 Varchar2(30) -- String
SET @ncCodeBo_1 = 'NCCodeBO:8110,SETUP_OSCILLOSCO'
WITH AllowedNcCode (Handle, NcCodeColumn, Description)
AS
(
SELECT DISTINCT
ncCode.HANDLE as NcCodeBo,
ncCode.NC_CODE as NcCode,
ncCode.DESCRIPTION as NcCodeDescription
FROM
WIPUSER.NC_CODE ncCode
INNER JOIN WIPUSER.NC_GROUP_MEMBER ncGroupMember ON ncCode.HANDLE = ncGroupMember.NC_CODE_OR_GROUP_GBO
WHERE
((ncGroupMember.NC_GROUP_BO IS NOT NULL AND ncGroupMember.NC_GROUP_BO = 'NCGroupBO:' || ncCode.SITE || ',CATAN_AUTO' OR ncGroupMember.NC_GROUP_BO IS NOT NULL AND ncGroupMember.NC_GROUP_BO = 'NCGroupBO:' || ncCode.SITE || ',CATAN_MAN') OR ncGroupMember.NC_GROUP_BO IS NOT NULL AND ncGroupMember.NC_GROUP_BO = 'NCGroupBO:' || ncCode.SITE || ',CATAN_ALL')
)
SELECT
item.Handle,
item.NcCodeColumn,
item.Description
FROM
AllowedNcCode item
WHERE
item.Handle = :ncCodeBo_1
If I change ncCodeBo and I print the SQL, I get the previous one because the SQL query is built when I assign the query to the variable result:
ncCodeBo = "NCCodeBO:8110,SETUP_OSCILLOSCO2";
sql = result.ToString();
Console.WriteLine(sql);
-- Wip Oracle.Managed Oracle
DECLARE @ncCodeBo_1 Varchar2(30) -- String
SET @ncCodeBo_1 = 'NCCodeBO:8110,SETUP_OSCILLOSCO' -- It should change to "NCCodeBO:8110,SETUP_OSCILLOSCO2"
WITH AllowedNcCode (Handle, NcCodeColumn, Description)
AS
...
My question is: is there a way to get an ExpressionQueryImpl<TElement>
with a method to call to set only the changing part of the query? For example the parameter ncCodeBo?
If the query is really huge, rebuilding the query only to change few parameters is time consuming.
Thank you!
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
vb.net - Parameterized SQL update query doesn't work
My code doesn't work in updating student records using parameterized SQL query in VB.Net. Dim result As Integer cmd = New OleDbCommand("UPDATE ......
Read more >SSRS cascading parameter doesn't change value when ...
I overtyped it with the value I want to use instead and run the report where the revised text appears. Screenshot3. I then...
Read more >Unable to Update Record in Access Database Using C# ...
Simplified the UPDATE query to only update one field; Changed the order of the parameters to match the order in the SQL statement....
Read more >Using multi-value parameters in SSRS
This article mentions usage of the multi-value parameter in the SSRS and it also include how to design a report with Report Builder....
Read more >Using Prepared Statements - JDBC Basics
This JDBC Java tutorial describes how to use JDBC API to create, insert into, update, and query tables. You will also learn how...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It is a bug in ToString(), we have to repopulate parameters for this call. Will fix that. First query is slow because we parse Expression Tree and provide optimizations. Second query just reuse parsed AST and generated SQL.
Hello @sdanyliv , Sorry, I don’t really need to log “all queries”, and sometime I need the SQL query without running the query. I have created this workaround that works very well:
I have discovered that only the first call to
result.ToString()
is slow but the second call is fast and gives me the right result. You should probably update the documentation to explain the ToString() behavior and to show how to update the ToString() result if parameters change.