3

I am stuck in a situation where my logic needs some improvement, which i am trying to do. The situation is we all know how to update the specific detail of column like this.

Person result = (from p in Context.Persons
          where p.person_id == 5
          select p).SingleOrDefault();

result.is_default = false;

Context.SaveChanges();

Okay, all good !

Now let's say I have a value in session is_default i.e the column name of the table.

How can I update the column using that value like so:

update table name set "Session value" = true 

Here the session value is is_default which is the column name of the table. Is this possible using EF , LINQ .

R.D
  • 226
  • 1
  • 17
Faizan
  • 542
  • 5
  • 16

1 Answers1

4

you can use the concept of reflection for this as given below

Person result = (from p in Context.Persons
          where p.person_id == 5
          select p).SingleOrDefault();

PropertyInfo propertyInfo = result.GetType().GetProperty("Session value");
propertyInfo.SetValue(result , true, null);
Akshey Bhat
  • 8,227
  • 1
  • 20
  • 20