' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
Imports System
Imports System.Data.Entity
Imports System.Linq

Namespace MT
    Public Class Program
        Public Shared Sub Main(args As String())
            ' open and close connection
            Using ctx As TestDbContext = new TestDbContext("TestDB")
                ' add a C1 and C2
                ctx.P.Add(New C1 With { .Id = 3, .Typ = 1, .Ival = 456 })
                ctx.P.Add(New C2 With { .Id = 4, .Typ = 2, .Sval = "DEF" })
                ctx.SaveChanges
                ' find by PK
                Console.WriteLine((From o In Ctx.P Where o.Id = 2 Select o).FirstOrdefault)
                ' list all
                For Each ox In (From o In Ctx.P Select o)
                    Console.WriteLine(ox)
                Next
                ' list all C2
                For Each ox In (From o In Ctx.C2 Select o)
                    Console.WriteLine(ox)
                Next
                ' list some
                For Each ox In (From o In Ctx.P Where 2 <= o.Id  And o.Id <= 3 Select o)
                    Console.WriteLine(ox)
                Next
            End Using
        End Sub
    End Class
End Namespace
