We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
public static class ProposalExtensions { public static void JustShowMeTheCode(IDbConnection cn) { var result = cn.Query( // allows to use anonymous type as result template: new { EmployeeName = "" }, param: new { EmployeeAge = 26 }, // allows to use 'nameof' for column names and parameter names sql: (t, p) => $"select e.name as {nameof(t.EmployeeName)} from tbl_emp e where e.age>@{nameof(p.EmployeeAge)}"); foreach (var item in result) { Console.WriteLine(item.EmployeeName); } } public static IEnumerable<T> Query<T,TParams>(this IDbConnection cnn, T template, Func<T,TParams,string> sql, TParams param, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CommandType? commandType = null) { return cnn.Query<T>(sql(default(T),default(TParams)),param,transaction,buffered,commandTimeout,commandType); } public static IEnumerable<T> Query<T>(this IDbConnection cnn, T template, Func<T,string> sql, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CommandType? commandType = null) { return cnn.Query<T>(sql(default(T)), param:null, transaction, buffered, commandTimeout, commandType); } }
The text was updated successfully, but these errors were encountered:
There seems to be two things here:
The first of these is much better approaches using named-tuples, which should already work; consider instead Query<(int Id, string Name)>(...)
Query<(int Id, string Name)>(...)
The second is arguably much harder to read, but fundamentally composing strings already works; the only new bit here is the template. Honestly, I wonder if this, if wanted, is better approached using the proposed custom string interpolation handler - maybe look here (draft only): https://github.com/DapperLib/DapperAOT/blob/sqlbuilder/test/Dapper.AOT.Test/SqlBuilderTests.cs
I doubt we'd add the PR proposed here into the core, but you can always use it in your own local extension method
Sorry, something went wrong.
No branches or pull requests
The text was updated successfully, but these errors were encountered: