Imports System.IO
Imports System.Reflection
Imports C1.LiveLinq
Imports C1.LiveLinq.AdoNet
Imports C1.LiveLinq.LiveViews


Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ' generated automatically
        productsTableAdapter.Fill(nORTHWNDDataSet.Products)
        categoriesTableAdapter.Fill(nORTHWNDDataSet.Categories)

        ' Create a live view for Categories.
        ' Each category contains a list with the products of that category. 

        C1.LiveLinq.AdoNet.AdoNetExtensions.AsLive(nORTHWNDDataSet.Categories)


        Dim categoryView =
            From c In nORTHWNDDataSet.Categories.AsLive()
            Group Join p In nORTHWNDDataSet.Products.AsLive()
                On c.CategoryID Equals p.CategoryID Into g = Group
            Select New With
            {
                c.CategoryID,
                c.CategoryName,
                .FK_Products_Categories = g
            }

        ' replace DataSource on the form to use our LiveLinq Query
        bindingSource1.DataSource = categoryView.AsDynamic()

    End Sub

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()
        AppDomain.CurrentDomain.SetData("DataDirectory", Environment.GetFolderPath(Environment.SpecialFolder.Personal) & "\ComponentOne Samples\Common")
        Dim dbFile As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal) & "\ComponentOne Samples\Common", "Northwnd.mdf")
        If Not File.Exists(dbFile) Then
            Throw New Exception("Sample database Northwnd.mdf must be created in the Common folder. Run the CreateSampleDB utility to create the Northwind database")
        End If

    End Sub
End Class
