lundi 3 avril 2017

Select column based on input enum parameter

I have table with columns

Id | UserId | GoogleEnabled | FacebookEnabled | TwitterEnabled

In code I want to select value of {provider}Enabled value - true/false base on input enum

enum Provider
{
   Google,
   Facebook,
   Twitter
}

private async Task CheckSettingsAsync(ISeedSession<IDbSession> seedSession, IUserInfo user, Provider provider){
...
var userSettingsTask = seedSession
                .Query<UserSettings>()
                .Where(us => us.UserId == user.UserId)
                .Select(us => us.GoogleEnabled) // if provider value is "Google"
                .SingleAsync();
...
}

Is there any pattern/solution better than create some switch to select my value?

Aucun commentaire:

Enregistrer un commentaire