Look the code below. I'd like to replace USERNAME
by the field name received in the parameter field
. This method must be able to make some search on several fields.
Thank,
public void Searching(string field, string stringToSearch)
{
var res =
from user in _dataContext.USERs where
user.USERNAME.Contains(stringToSearch)
select new
{
Id = user.ID,
Username = user.USERNAME
};
}
What you are trying is not possible. You can however use the dynamic linq library to achieve what you want
As a matter of fact it is possible using the Expression API:
You need to forget about the anonymous type, maybe use
Tuple<int,string>
instead; but: how about: