I made this query to get data from a table
List<MyTable> liDeatil = Db.Database.SqlQuery<MyTable>("SELECT * FROM [myDB].[dbo].[MyTable]").ToList();
From liDetail i want to select column dynamically such as
liDeatil.Select(s => new myclass{ Id = s.Id ,Marks = ....}).Tolist();
Where MyClass is
public class MyClass
{
public Nullable<decimal> Id { get; set; }
public string Marks { get; set; }
public string rank { get; set; }
}
is there any way to get the column
pls help me
I tried To do this by reflection But its not working
var ss = liDeatil.Select(s => new MyClass{ Id = s.Id ,Marks = s.GetType().GetProperties("ColumnMarks")}).Tolist();
EDITED
public class MyTable
{
public Nullable<decimal> Id { get; set; }
public string ColumnMarks{ get; set; }
public string ColumnMarks1{ get; set; }
public string ColumnMarks2{ get; set; }
}