DapperLib / DapperAOT

Build time tools in the flavor of Dapper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hello just trying to esatablish how to use this as there are no code examples

jdurnil opened this issue · comments

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();

    var con = new SqlConnection(_connectionString);
    con.Open();
    var list = new List<Program>();
    var test = con.Command<Program>("SELECT Name, Acronym FROM Programs");
    var test2 = test.Execute(programs);

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

I get this when trying to use query off dbconnection
image

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
image

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
image

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" />

Sorry for lack of documentation; we'll get there, but that isn't our top priority just yet