Hi All,
public DataTable GetTable() { DataTable table = new DataTable(); table.Columns.Add("Dosage", typeof(int)); table.Columns.Add("Drug", typeof(string)); table.Columns.Add("Patient", typeof(Info)); table.Columns.Add("Date", typeof(DateTime)); table.Rows.Add(25, "Indocin", new Info("India"), DateTime.Now); table.Rows.Add(50, "Enebrel", new Info("UK"), DateTime.Now); table.Rows.Add(10, "Hydralazine", new Info("Bhutan"), DateTime.Now); table.Rows.Add(21, "Combivent", new Info("India"), DateTime.Now); table.Rows.Add(100, "Dilantin", new Info("GreenLand"), DateTime.Now); return table; }Info class as follows
public class Info { public string Address { get; set; } public Info(string Add) { this.Address = Add; } }Now, I want to do the filtering operation based on Address Field, i.e Patient.Address
Here, Patient is object of Info class.
I have formed the predicates as follows
filterPredicate = As below in the image

paramExpression = formed using dataSource.AsQueryable().Parameter(); got the below output.

After executing the below line.
data = dataSource.AsQueryable().Where(paramExpression, filterPredicate);
finally query string formed as follow
((System.Linq.EnumerableQuery)(data)) {System.Data.EnumerableRowCollection`1[System.Data.DataRow].Where(DataRow => (DataRow.Field("Patient.Address").ToLower() == "india"))} System.Linq.EnumerableQuery {System.Linq.EnumerableQuery
At last, I got the message stating that,
Message = "Column 'Patient.Address' does not belong to table."
Could you please share your idea, is it possible to filter the DataTable with complex field?
Regards
Kalai Selvi
Manas MohapatraPosted Dec 22, 2016, 12:58 PM
where myRow.Field
select myRow;
foreach (DataRow dr in results2)
{
Console.WriteLine(dr["Name"]);
}