Closed AsuraKev closed 7 months ago
Can you please provide more details? I didn't get what you're trying to do, or what's the problem you're having.
If you want to run two queries in a single roundtrip you can use Dapper QueryMultiple()
. But running two commands over the same connection also should work.
Hey @Drizin, thanks for the reply. Let me clarify my use case.
Based on the docs, to initialise a new query builder it goes like below where a SqlBuilder will be created on the current connection *cn.SqlBuilder($"SELECT FROM Product WHERE CategoryId={categoryId}")**
To extend on this pattern I was trying to do
var connection = new DBConnection();
var query1 = connection.SqlBuilder("
var query2 = connection.SqlBuilder("
query1.QueryAsync
This is where I noticed that query1 has became null upon inspecting... I was thinking that for a given existing DBConnection, we can create as many SqlBuilder on it. If this usage makes sense...
thanks :)
That looks odd. How can a variable become null for no reason?
Can you create (and share here) a unit test where I can see the problem?
I tested this and haven't found any issues:
[Test]
public async Task TestNullVariable()
{
var q1 = cn.QueryBuilder($"SELECT ProductID FROM [Production].[Product]");
q1.Where($"ProductId=1");
var q2 = cn.QueryBuilder($"SELECT ProductID FROM [Production].[Product]");
q2.Where($"ProductId=2");
var res1 = await q1.QueryAsync<int>();
var res2 = await q2.QueryAsync<int>();
}
hmm I gave it a shot again, it looks like its working fine now. I must have screwed up something before. thanks for the help and clarification! :)
Hi there, First of all I am using dapper :)
I am doing two dynamic pagination queries where one will fetch the total count and another one with pagination result. This is how I am trying it out
However I realised that the paginationQuery variable is null and I assume that the totalQuery has been picked up. Is there any way we can run multiple query build on same IDConnection instance?
thanks!