0

少し背景を説明します。私は Web 開発者で、彼の最初の に取り組んでいWinformます。

を使用してEF5います。テーブルはリレーショナルですが、テーブルには主キーしかありません。が付属していますWinformGridViewこれGridViewは によって移入されていBindingSourceます。のDatasourceBindingSource、Linq クエリによって埋められています。


Public Class Form1
    Private batchEnt As BatchMananger.PrintManagerEntities
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        Try

            batchEnt = New BatchMananger.PrintManagerEntities

            batchBindingSource.DataSource = (From b In batchEnt.AutomatedBatches Join bd In batchEnt.AutomatedBatchResults On b.ID Equals bd.AutomatedBatchID Where b.BatchName <> "" Select b.ID, b.BatchName, b.Description, b.ScheduleDesc, b.BatchResultEmail, b.BatchSourceEmail, bd.ExecutionDateTime, bd.TotalSuccesful, bd.TotalItems, bd.TotalFail).ToList
        Catch ex As Exception
            Throw
        End Try
    End Sub
End Class

私の問題は、結合されたテーブルからではなく、テーブルGridviewからのデータのみが取り込まれていることです。ただし、要素を調べると、結合された結果が返されていることがわかります。クエリからのすべての結果が my に入力されるように、にバインドするにはどうすればよいですか。AutomatedBatchesAutomatedBatchResultsDatasourceBIndingsourceLinqGridview

さらに情報が必要な場合はお知らせください。

アップデート

何が間違っていたかがわかった。GridView のプロパティに DataPropertyName を設定していませんでした。DataPropertyName をデータベース フィールドと同じ名前に設定すると、機能しました。また、EF データ モデルで、AutomatedBatch (1) と AutomatedBatchResult (多数) の間の関連付けも作成しました。

4

2 に答える 2

0

何が間違っていたかがわかった。GridView のプロパティに DataPropertyName を設定していませんでした。DataPropertyName をデータベース フィールドと同じ名前に設定すると、機能しました。また、EF データ モデルで、AutomatedBatch (1) と AutomatedBatchResult (多数) の間の関連付けも作成しました。

于 2013-02-27T16:01:41.370 に答える
0

データが表示されない場合、推測では、結合されたテーブルの一部のレコードが表示されない原因となっている結合要求です。linq の join キーワードは内部結合であるため、結合条件を満たさないレコードは表示されないことに注意してください。テーブルのすべてのレコードを表示するには、次のようにします。

クイック ノート -- すべてのオブジェクトにタイプを追加してください。

Private batchEnt As BatchMananger.PrintManagerEntities
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

        Try
            Dim batchEnt As PrintManagerEntities = New PrintManagerEntities
            Dim batchBindingSource

            Dim batcheswithResults = (From b In batchEnt.AutomatedBatches
                                             Join bd In batchEnt.AutomatedBatchResults  On b.ID Equals bd.AutomatedBatchID
                                             Where b.BatchName <> ""
                                             Select New Results(b, bd)).ToList

            Dim batchesWithoutResults = (From b In batchEnt.AutomatedBatches
                                         Where Not batchEnt.AutomatedBatchResults.Any(Function(o) o.Id = b.Id)
                                         Select New Results(b, Nothing)).ToList

            Dim itemsSource As New List(Of Object)
            itemsSource.AddRange(batcheswithResults)
            itemsSource.AddRange(batchesWithoutResults)

            batchBindingSource.DataSource = itemsSource

        Catch ex As Exception
            Throw
        End Try
    End Sub

End Module

Public Class Results
    'TODO: Add types to params and all properties
    Public Sub New(AutomaticBatches, AutomatedBatchResults)
        _automaticBatches = AutomaticBatches
        _automatedBatchResults = AutomatedBatchResults
    End Sub

    Private _automaticBatches
    Private _automatedBatchResults

    Public Property ID
        Get
            Return _automaticBatches.ID
        End Get
        Set(value)
            _automaticBatches.ID = value
        End Set
    End Property
    Public Property BatchName
        Get
            Return _automaticBatches.BatchName
        End Get
        Set(value)
            _automaticBatches.BatchName = value
        End Set
    End Property
    Public Property Description
        Get
            Return _automaticBatches.Description
        End Get
        Set(value)
            _automaticBatches.Description = value
        End Set
    End Property
    Public Property ScheduleDesc
        Get
            Return _automaticBatches.ScheduleDesc
        End Get
        Set(value)
            _automaticBatches.ScheduleDesc = value
        End Set
    End Property
    Public Property BatchResultEmail
        Get
            Return _automaticBatches.BatchResultEmail
        End Get
        Set(value)
            _automaticBatches.BatchResultEmail = value
        End Set
    End Property
    Public Property BatchSourceEmail
        Get
            Return _automaticBatches.BatchSourceEmail
        End Get
        Set(value)
            _automaticBatches.BatchSourceEmail = value
        End Set
    End Property
    Public Property ExecutionDateTime
        Get
            If _automatedBatchResults IsNot Nothing Then Return _automatedBatchResults.ExecutionDateTime
            Return Nothing
        End Get
        Set(value)
            If _automatedBatchResults IsNot Nothing Then _automatedBatchResults.ExecutionDateTime = value
        End Set
    End Property
    Public Property TotalSuccesful
        Get
            If _automatedBatchResults IsNot Nothing Then Return _automatedBatchResults.TotalSuccesful
            Return Nothing
        End Get
        Set(value)
            If _automatedBatchResults IsNot Nothing Then _automatedBatchResults.TotalSuccesful = value
        End Set
    End Property
    Public Property TotalItems
        Get
            If _automatedBatchResults IsNot Nothing Then Return _automatedBatchResults.TotalItems
            Return Nothing
        End Get
        Set(value)
            If _automatedBatchResults IsNot Nothing Then _automatedBatchResults.TotalItems = value
        End Set
    End Property
    Public Property TotalFail
        Get
            If _automatedBatchResults IsNot Nothing Then Return _automatedBatchResults.TotalFail
            Return Nothing
        End Get
        Set(value)
            If _automatedBatchResults IsNot Nothing Then _automatedBatchResults.TotalFail = value
        End Set
    End Property

End Class
于 2013-02-27T11:58:39.043 に答える