Closed jdurnil closed 1 year ago
I get this when trying to use query off dbconnection
I can only get Command off dbconnection. I am using Microsoft.Data.SqlClient as it is all that will really work in linux aot
And my using statements are Using Dapper; Using System.Data Using System.Data.Common
And Dapper.Aot is installed in the project
Hello, I'm just a normal user here. But I can give you what I did to make it work on my side.
First you need to enable the interceptor feature by adding <Features>InterceptorsPreview</Features>
in your csproj. See the announcement.
Be sure to use the latest prerelease version (0.5.0-beta.49 on my side).
And lastly, add the [DapperAot]
attribute on method containing you normal dapper query.
But before all theses steps, you should try to make your app work first without DapperAot. You app should compile already compile before any step to add aot support.
I have tried addind [DapperAot] over the method but the only Query methods are inside the Command class
none of the query methods are extensions of DBConnection
public IEnumerable<TRow> Query<TRow>(TArgs args, bool buffered, RowFactory<TRow>? rowFactory = null);
Only the Command methods are extensions of DBConnection
public static Command<T> Command<T>(DbConnection connection, DbTransaction? transaction, string sql, CommandType commandType = 0, int timeout = 0, CommandFactory<T>? handler = null);
So
Query is not an option in the normal way you use Dapper, so my question is how do i use this?
Classic dapper extensions methods are in Dapper.SqlMapper
class. Try to call them as not extension method first.
Like this Dapper.SqlMapper.Query(con, "sql");
But it's not an issue with DapperAOT
Also, Query is part of Dapper
if you look at https://github.com/DapperLib/DapperAOT/blob/main/src/Dapper.AOT/, you will see there is no definition for Dapper.SqlMapper in the AOT package, if you look through the source code you can see the only way to h=gert at the quert method is to create a command object both which take a generic and the query method accepts some weird Targs paramater. Again Dapper.SqlMapper is not defined in Dapper.AOT, Do I have to have regular Dapper installed too?
This is normal. You need classic Dapper first. And each call to SqlMapper will be replaced by a source generated one. The Trimming post processing will do the cleanup.
On my side I have both package referenced
<PackageReference Include="Dapper" Version="2.0.143" />
<PackageReference Include="Dapper.AOT" Version="0.5.0-beta.49" />
Thank you!! Everything works now.
On Fri, Aug 11, 2023 at 6:19 PM Rémy de Sérésin @.***> wrote:
This normal. You need classic Dapper first. And each call to SqlMapper will be replaced by a source generated one. The Trimming post processing will do the cleanup.
On my side I have both package referenced
— Reply to this email directly, view it on GitHub https://github.com/DapperLib/DapperAOT/issues/29#issuecomment-1675464616, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB7DCFZFAW77E2WSXNFPPVDXU2VYZANCNFSM6AAAAAA3LNPQ2I . You are receiving this because you authored the thread.Message ID: @.***>
Sorry for lack of documentation; we'll get there, but that isn't our top priority just yet
I have seen that the code is obviously not constructed the same as normal dapper I have tried this with the [DapperAot] attribute over my model var programs = new List();
but it returns nothing, there is no "Query method off of sql connection like normal Dapper. How doo i get this to work on just very basic simple terms. Can you please give a ver basic code example of getting DapperAot to work, there is nothing in the readme