vendredi 7 septembre 2018

How to get the value of column name using reflection

I have a scenario in which when user loggedin to the app a session named session["role"] is created for him/her.

If he/she is Admin than the session["role"] value will be "Admincheck".

If he/she is User than the session["role"] value will be "Usercheck".

I also have a table namely Notification in which there are two boolean columns namely Admincheck and Usercheck.

Now I created a logic that on loggedin I am going to check the session value and comparing it with the column name of table and going to show all the records which is false for that column.

What I tried is here . This is going to get all the Notifications of that table

var records = repository.GetAll()

Now I am getting all properties of my model

Type T = Type.GetType("Notifications")
PropertyInfo Properties = T.GetProperties();

Since my value of session and column name are similar so I am comparing them one by one

foreach(PropertyInfo prop in Properties)
{
   if(prop.Name.Eqals(Session["role"]))
  {
       //In the first step  I get ll records

       // in this step i need to filter that all records and want to get all 
           the records of specific column that is equal to the session value  
           //lets say the user was admin so i need to get all the records of 
                db in which `Adminheck` is false
  }
}

Any clue will be appreciable .





Aucun commentaire:

Enregistrer un commentaire