I\'m using LINQ to SQL in C# in my application. I need to be able to select a column of a row, depending upon a variable. This is easy for the row as it\'s a simple where cl
Say the class that holds the permissions is named Permission, you can define an extension method:
public static class PermissionExtensions
{
public static object SelectProperty(this Permission obj, string variable)
{
return obj.GetType().GetProperty(variable).GetValue(obj, null);
}
}
You can use this in your query like this:
(from s in dc.Permissions where s.dashboardname == permission select s)
.Single().SelectProperty(variable);
This doesn't select the property in the query but instead gets it from the instance.