DataView.RowFilter - 具有多个父关系的问题 [英] DataView.RowFilter – problem with more than one parent relation
问题描述
嗨
在文档
http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx
我读到我们可以使用前缀父或子从RowFilter属性引用到另一个表。
In documentation http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx I read that we can use prefix parent or child to refer from RowFilter property to another table.
我创建了一个简单的例子,但我对子关系有问题。
I created simple example but I have problem with child relation.
我有三张桌子:
I have three tables:
设备(id,deviceName,deviceTypeId),接口(id,deviceId,interfaceName)和DeviceType(id,
名称)
Devices (id, deviceName, deviceTypeId), Interfaces(id, deviceId, interfaceName), and DeviceType(id, name)
Interfaces.deviceId和Devices.meviceTypeId是关系和外键约束。
我的样本:
DataSet1 ds = new DataSet1();
ds.DeviceType.Rows.Add("1", "type1");
ds.DeviceType.Rows.Add("2", "type2");
ds.Devices.Rows.Add("1", "device1", "1");
ds.Interfaces.Rows.Add("1", "1", "device1_interface1");
ds.Interfaces.Rows.Add("2", "1", "device1_interface2");
ds.Devices.Rows.Add("2", "device2", "2");
ds.Interfaces.Rows.Add("3", "2", "device2_interface1");
ds.Interfaces.Rows.Add("4", "2", "device2_interface2");
ds.AcceptChanges();
Console.WriteLine("PARENT RELATION");
DataView viewIntefaces = new DataView(ds.Interfaces);
viewIntefaces.RowFilter = "Parent(FK_Devices_Interfaces).deviceName = 'device1'";
foreach (DataRowView rowView in viewIntefaces)
{
Console.WriteLine(rowView["interfaceName"]);
}
Console.WriteLine("PARENT x2 RELATION");
//Here I get exception:
viewIntefaces.RowFilter = "Parent(FK_Devices_Interfaces).Parent(DeviceType_Devices).name = 'type2'";
foreach (DataRowView rowView in viewIntefaces)
{
Console.WriteLine(rowView["interfaceName"]);
}
推荐答案
如果您想根据祖父母标准过滤孙子项目,那么a dataviewmanager可能更有用;
If you want to filter grandchildren items based on grandparent criteria, then a dataviewmanager might be more useful;
dataviewmanager是数据集,数据视图是数据表的内容。
a dataviewmanager is to a dataset, what a dataview is to a datatable.
这篇关于DataView.RowFilter - 具有多个父关系的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!