Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net GridView中的Linq到SQL对象子属性_.net_Sql_Linq_Wcf_Linq To Sql - Fatal编程技术网

.net GridView中的Linq到SQL对象子属性

.net GridView中的Linq到SQL对象子属性,.net,sql,linq,wcf,linq-to-sql,.net,Sql,Linq,Wcf,Linq To Sql,例如,在我的WCF中,如果我有一个客户表和一个订单表,它们在客户ID上相互关联 我想得到每个客户的订单数量 在常规VB代码中,我可以这样做: Dim CustID As Integer = 1234 Dim cust As New MyService.Customer() cust = cust.GetCustomer(CustID) Response.Write(cust.Orders.Count) 上面的代码工作得很好,但如果我想从GridView中访问相同的代码,它的反应似乎并不相同(a

例如,在我的WCF中,如果我有一个客户表和一个订单表,它们在客户ID上相互关联

我想得到每个客户的订单数量

在常规VB代码中,我可以这样做:

Dim CustID As Integer = 1234
Dim cust As New MyService.Customer()
cust = cust.GetCustomer(CustID)
Response.Write(cust.Orders.Count)
上面的代码工作得很好,但如果我想从GridView中访问相同的代码,它的反应似乎并不相同(albiet,来自不同的方法,但我对每个方法应用相同的原则)


...
...

那么我该怎么做呢?

您可以尝试向名为OrderCount的Customer类添加一个分部方法,并在BoundField中引用该方法。右键单击dbml文件,进入查看代码,然后添加

VB

C#


还有其他解决办法吗?我的意思是,有没有其他方法可以像在中继器中一样通过服务器标签Text=”“设置值本身应该可以。
<asp:ObjectDataSource ID="odsCustomers" runat="server" SelectMethod="GetCustomers" TypeName="MyService.Customer" />

<asp:GridView ...>
...
<Columns>
    <asp:BoundField DataField="Orders.Count" HeaderText="Order Count" />
</Columns>
...
</asp:GridView>
Partial Public Class Customer

    Public ReadOnly Property OrderCount As Integer
        Get
            Return Me.Orders.Count
        End Get
    End Property

End Class
public partial class Customer
{
    
    public int OrderCount {
        get { return this.Orders.Count; }
    }
}