Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jdurnil opened this issue Aug 10, 2023 · 10 comments
Closed

Comments

@jdurnil
Copy link

jdurnil commented Aug 10, 2023

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

@jdurnil
Copy link
Author

jdurnil commented Aug 10, 2023

I get this when trying to use query off dbconnection
image

@jdurnil
Copy link
Author

jdurnil commented Aug 10, 2023

I can only get Command off dbconnection. I am using Microsoft.Data.SqlClient as it is all that will really work in linux aot

@jdurnil
Copy link
Author

jdurnil commented Aug 10, 2023

And my using statements are
Using Dapper;
Using System.Data
Using System.Data.Common

And Dapper.Aot is installed in the project

@latop2604
Copy link

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.

@jdurnil
Copy link
Author

jdurnil commented Aug 11, 2023

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?

@latop2604
Copy link

latop2604 commented Aug 11, 2023

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

@jdurnil
Copy link
Author

jdurnil commented Aug 11, 2023

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?

@latop2604
Copy link

latop2604 commented Aug 11, 2023

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

@jdurnil
Copy link
Author

jdurnil commented Aug 12, 2023 via email

@mgravell
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants