Reputation: 37
How do I use a variable field to access data? I do not know which column I will be searching which is why this is neccessary
db.tbl.FirstOrDefault(r => r.(variable) == "live");
Upvotes: 1
Views: 177
Reputation: 668
If you would like to select just one or a few properties which map to columns you can do the following;
var emails = context.Person.Select(x => new
{
x.Emails
});
This returns an collection of object with Email property.
Hope this helps
Upvotes: 0
Reputation: 17658
You can try dynamic linq:
It allows you to write queries like:
db.tbl.Where("some_column_name = live").FirstOrDefault();
See: https://weblogs.asp.net/scottgu/dynamic-linq-part-1-using-the-linq-dynamic-query-library
Upvotes: 1