我想过滤包含复杂对象的DataTable或DaatView。在DataTable/DataView中过滤复杂对象
比方说,我有这样的对象者
public class Person{
public int Id{get; set;}
public int Age{get; set;}
public strng Name{get; set;}
public Address BillAddress{get; set;}
}
public class Address{
public string
Town{get; set}
public string Street{get; set}
public int Number{get; set}
}
现在我填一个DataView与Person对象的列表:
public static DataView ToObjectDataView<T>(this IList<T> list, int countOfColumns)
{
if (list == null || countOfColumns < 1)
{
return null;
}
int columns = countOfColumns;
DataTable dataTable = new DataTable();
for (int currentCol = 0; currentCol != columns; currentCol++)
{
DataColumn column = new DataColumn(currentCol.ToString(), typeof(T));
dataTable.Columns.Add(column);
}
DataRow row = null;
int currentColumn = 0;
for (int index = 0; index < list.Count; index++)
{
if (list[index] == null)
{
continue;
}
if (Equals(null, row))
row = dataTable.NewRow();
row[currentColumn] = list[index];
currentColumn++;
if (currentColumn == columns)
{
dataTable.Rows.Add(row);
row = null;
currentColumn = 0;
}
}
//Verarbeitung der letzten Zeile
if (!Equals(null, row))
{
dataTable.Rows.Add(row);
}
return new DataView(dataTable);
}
让我与Person对象的10列的数据视图, evrey专栏有它的索引名称:
IList<Person> personList = new List<Person>();
// Fill the list...
DataView dataSource = personList.ToObjectDataSource(10);
现在我想过滤这个DataVi例如,根据孩子的价值观和表达方式,让所有居住在'假客户'的人都能获得。
我试过“0.BillAddress.Street =‘Fakestreet’”(和或与其他列表达),但不工作..