We have moved to GitHub Issues
Created by Sébastien Sougnez 13 Jul 2018, 08:41:20 Updated by Sebastiaan Janssen 15 Jul 2018, 05:53:26Tags: Up For Grabs PR
this is not really an issue but more a proposal (if it's not the right place to do so, please tell me where to do it).
PetaPoco is really nice to work with, however, I feel that having to specify the name of the columns to select as string is error prone and a bit of a shame when the rest of the API uses delegate. Therefore, I quickly created a method (for now, it's heavily using reflection as it was just a test) used to select fields based on delegates. Basically, this can be used like this:
var cmd = new Sql().Select<NewsletterSubscription>(dbc.SqlSyntax, x => x.Id, x => x.Email);
Of course, some override could be created to support multi table, such as:
var cmd = new Sql().Select<T1, T2>(dbc.SqlSyntax, x => x.Field1, x => x.Field2, y => y.Field1);
I'm going to use it for my project but I wondered if it was something that could be useful to more people than just me. If so, I could create a PR to add this to Umbraco.Core?
What do you guys think?
@ssougnez Sure, that's a great idea! We're using this in v8 already and maybe you can get some inspiration from the extension method there: https://github.com/umbraco/Umbraco-CMS/blob/temp8/src/Umbraco.Core/Persistence/NPocoSqlExtensions.cs#L666
We've switched to NPoco for v8, so it's not exactly the same but it might help.
Look forward to seeing a PR!
@sebastiaan Cool, then I'll create a PR soon :-D
You wanted it, you got it :-D
Backwards Compatible: True
Due in version: 7.12.0