我在SQL Server中有两个表,比如A和B. B是文档列表,A包含指示项目是否应该在B中包含行的数据。
A
___________
AId int PK,
BId int,
Include bit
B
___________
BId int PK,
BDocNumber varchar(10),
BName varchar(128)
我有A和B的POCO,但最终我所能追求的是我可以绑定到包含两者数据的devExpress网格(BDocNumber,BName,Include)
我可以将B设置为导航属性,但我不知道如何将其展平为网格(DevExpress ASPxGridView,服务器模式)
我也研究过实体拆分,但看起来不行,因为我想加入BId而不是AId。
对1或2的解决方案是可以接受的,但是了解两者都会很棒。
由于
答案 0 :(得分:1)
您所拥有的是您想要在DevExpress网格中访问的A到B中的“has-a”关系或一对一导航属性。您可以通过将FieldName属性设置为NavigationProperty.FieldName
来完成此操作说出Persont与地址之间的一对一关系,如下所示:
public class Person
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public virtual Address Address { get; set; }
}
public class Address
{
public int ID { get; set; }
public string StreetAddress { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
}
您的aspx页面中的GridView包含地址导航属性的Person和StreeAddress属性将如下所示
<dx:ASPxGridView ID="ASPxGridView1" runat="server">
<Columns>
<dx:GridViewDataTextColumn FieldName="FirstName" VisibleIndex="0">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="LastName" VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Address.StreetAddress" VisibleIndex="1">
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
在这种情况下,Person是表A,Address是表B.你在A上绑定gridview,那么你将把你的字段名设置为B.FieldToDisplay。
希望这有帮助!