Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.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
Asp.net 使用BLL、DAL在gridview中显示外键的值_Asp.net_.net_Gridview - Fatal编程技术网

Asp.net 使用BLL、DAL在gridview中显示外键的值

Asp.net 使用BLL、DAL在gridview中显示外键的值,asp.net,.net,gridview,Asp.net,.net,Gridview,我有三张桌子:汽车型号、汽车品牌和汽车类型 Car_模型有两个外键指向其他两个表。 我想在gridview中显示car_模型的所有内容,而不是其他两个表的外键,而是它们的值 目前我的DAL中有以下功能: Private dc As New ModelDataContext Public Function selectAll() As List(Of Model) Dim result = From p In dc.Models

我有三张桌子:汽车型号、汽车品牌和汽车类型

Car_模型有两个外键指向其他两个表。 我想在gridview中显示car_模型的所有内容,而不是其他两个表的外键,而是它们的值

目前我的DAL中有以下功能:

Private dc As New ModelDataContext

    Public Function selectAll() As List(Of Model)

        Dim result = From p In dc.Models
                     Join a In dc.Brands
                     On p.car_brand Equals a.Car_Brand_Id
                     Join t In dc.Types
                     On p.Car_type Equals t.Car_Type_id
                     Select p

        Return result.ToList
    End Function
我的BLL中包含以下内容:

Public Function selectAll() As List(Of Model)

    Return DALm.selectAll

End Function

通常,关系可以这样映射:

Class Model
    Public Property Brand As Car_Brand
    Public Property Type As Car_Type
    ...
End Class
但是,如果您想自己获取它们,可以创建一个中间类,如下所示:

Class Car_ViewModel
    Public Property Car As Model
    Public Property Brand As Car_Brand
    Public Property Type As Car_Type
End Class
然后在您的查询中:

Public Function selectAll() As List(Of Car_ViewModel)

    Dim result = From p In dc.Models
                 Join a In dc.Brands
                 On p.car_brand Equals a.Car_Brand_Id
                 Join t In dc.Types
                 On p.Car_type Equals t.Car_Type_id
                 Select New Car_ViewModel With { .Car = p, .Brand = a, .Type = t }

    Return result.ToList
End Function

具有以下内容的网格视图:汽车模型id汽车模型设计门汽车品牌(fk id值)|汽车类型(fk id值)