I want select Col1 or Col2 by dynamic in linq command for example
var temp1= "Col1";
thank you for answer
I try by
((ICollection<SanadItem>)x.GetType().GetProperty(temp1).GetType()).Select(g =>...
but get error LINQ to Entities does not recognize the method 'System.Type GetType()' method
public class class1 {
public int Id {get; set;}
public string Name {get; set;}
public string Code {get; set;}
public ICollection<Class2> Col1 {get; set;}
public ICollection<Class2> Col2 {get; set;}
}
public class class2 {
public int Id {get; set;}
public int Id2 {get; set;}
public int Bed {get; set;}
public int Bes {get; set;}
}
...
..
.
public class mycontext:dbcontext{
public DbSet<Class1> class1 { get; set; }
public DbSet<Class2> class2 { get; set; }
}
var db = new mycontext()
var qbase = db.class1;
var qbase2 = qbase.Select(x => new
{
Id = x.Id,
Code = x.Code,
Name = x.Name,
//--> I want select x.Col1 or x.Col2 by Dynamic but I cannot use library Linq.Dynamic
items = x.Col1.Where(xx => xx.Id2 == x.Id).GroupBy(b=>b.Id2).Select(y =>
new
{
Bed = y.Sum(c=>c.Bed),
Bes = y.Sum(c => c.Bes),
})
});