By now you've read the blog posts, the documentation, and seen some of the samples.  I thought I would post a quick console sample that shows some code that uses Northwind and Jasper.  The code snippet below is a simple console application that does a number of things: 

  • It returns all the customers and their associated orders and writes out their values
  • Next performs another query and only returns the customers, along with their associated orders, that are from a specific country
  • Finally we perform the same query as above but order the results by the contact name.

Notice how simple it is to write the code.  In this case I'm generating a default Entity Data Model (with some naming fix ups) by specifying "Generate Default EDM=True" in my connection string.  However, if I had wanted to provide a custom Data Model (I'll show this in a future post) you can specify that by specifying the location of my model (just as you would for a normal Entity Client connection string).  All classes are generated against either the model we generate at runtime or the user provided model. 

 

Imports Microsoft.Jasper

Module JasperSample

Dim connectionString As String = "Provider='System.Data.SqlClient';Provider Connection String='Data Source=.\SQLExpress;Initial Catalog=Northwind;Integrated Security=True;';Generate Default EDM=True;"

Dim context

 

Sub Main()

context = DynamicContext.CreateDynamicContext(connectionString)

WriteAllCustomers()

WriteCustomersFromSpecificCountry("France")

WriteCustomersFromCountryOrdered("Sweden")

Console.WriteLine("press any key to continue...")

Console.ReadKey()

End Sub

 

Sub WriteAllCustomers()

For Each customer In context.Customers

Console.WriteLine("Customer " & customer.ContactName & " from " & customer.Region & " has the following orders:")

For Each order In customer.Orders

Console.WriteLine(vbTab & "Order was placed on " & order.OrderDate & "and need to be delivered by " & order.RequiredDate)

Next

Next

End Sub

 

Sub WriteCustomersFromSpecificCountry(ByVal country As String)

For Each customer In context.Customers.Where("it.Country = @Customers", New Objects.ObjectParameter("Customers", country))

Console.WriteLine("Customer " & customer.ContactName & " from " & customer.Region & " has the following orders:")

For Each order In customer.Orders

Console.WriteLine(vbTab & "Order was placed on " & order.OrderDate & "and need to be delivered by " & order.RequiredDate)

Next

Next

End Sub

 

Sub WriteCustomersFromCountryOrdered(ByVal country As String)

For Each customer In context.Customers.Where("it.Country = @Customers", New Objects.ObjectParameter("Customers", country)).OrderBy("it.ContactName")

Console.WriteLine("Customer " & customer.ContactName & " from " & customer.Region & " has the following orders:")

For Each order In customer.Orders

Console.WriteLine(vbTab & "Order was placed on " & order.OrderDate & "and need to be delivered by " & order.RequiredDate)

Next

Next

End Sub

 

End Module

 

In my next blog post I'll post some samples using Jasper with ASP.NET and Windows Forms.  I'll also be talking about applying your own custom business logic and how easy that is.  Stay tuned!

 

Carl Perry