2008-12-08 58 views

回答

0

通過添加兩個引用,你說選擇PK = this和PK =的所有行。由於Pk是唯一的,所以條件將始終是錯誤的。

我不知道LINQ真的很好,但在SQL你會引用表兩次,別名它作爲

.... FROM tblstaff STAFF1,tblstaff staff2

+0

我正在使用linq實體框架,因此visual studio中的數據庫點獲取所有關係並基於這些表和關係創建對象。 – 2008-12-11 15:18:36

1

我不得不創建一個函數getStaffbyID並手動調用它時,我想要的名稱,而不是id。

Dim id As String = 1 
    Session("BusinessPlanID") = id 

    Dim oLinq As New Linq 
    Dim bp As BusinessPlan = oLinq.getBusinessPlanById(id) 

    Dim assignedStaff As Staff = oLinq.getStaffById(bp.AssignedStaffID) 
    Dim mp As Staff = oLinq.getStaffById(bp.MPStaffID) 

    Public Function getBusinessPlanById(ByVal inId As String) As BusinessPlan 

     Dim db As New BusinessPlanDataDataContext 

     Dim bpItem = (From b In db.BusinessPlans _ 
         Select b _ 
         Where b.BusinessPlanID = inId).SingleOrDefault 

     Return bpItem 

    End Function 

    'Linq Class --------------------------------------------------------' 

    Public Function getStaffById(ByVal inId As String) As Staff 

     Dim db As New BusinessPlanDataDataContext 

     Dim staffItem = (From s In db.Staffs _ 
         Select s _ 
         Where s.StaffID = inId).SingleOrDefault 

     Return staffItem 

    End Function