Harugawa
Harugawa

Reputation: 539

Custom string in linq to entity select new

Is there any way to customize it?

This is what Im trying to do:

string customSelect = "c.person_name";
int per = PersonID();
var RetrievItem = (from c in db.person where c.person_id == per select new { customSelect }).FirstOrDefault();

I've tried to debugging it but it just ended up retrieving given string instead of value from database

Any suggestions @_ @?

Upvotes: 0

Views: 467

Answers (1)

bkaf
bkaf

Reputation: 486

In addition to Hamlet's comment about an expression based solution, you can have a look at the Dynamic Linq library. It supports lamba expressions defined as strings, which is exactly what you need.

Upvotes: 3

Related Questions