Differences between revisions 10 and 11
Revision 10 as of 2008-06-03 17:20:31
Size: 3766
Editor: KaiJaeger
Comment:
Revision 11 as of 2008-08-20 18:57:18
Size: 3702
Editor: anonymous
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
##acl MoinPagesEditorGroup:read,write,delete,revert All:read

Microsoft's Project Jasper

Currently an incubation project of the Data Access and Storage section at Microsoft, Jasper is a set of .NET classes "geared towards interative and agile development". For the download links check: http://msdn2.microsoft.com/en-us/data/bb419139.aspx

The idea behind the project is to have the runtime generate all the data access classes without the need for the developer to write them manually. In fact it's easier to show a sample, in our beloved Dyalog 11 than to read the documentation. I translated the sample from the example in Python (which is a lovely language, easy to read and understand).

In order to iterate through the collections returned by the various methods, let's first define a sample operator foreach.

  •  r←(fn foreach)coll;x
     r←⍬
     :For x :In coll
         r,←⊂fn x
     :EndFor

MortenKromberg suggest an alternative coding for the operator foreach based on the semantics of the monadic squad:

  •  foreach←{⍺⍺¨⌷⍵}

conn is the connection string:

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

Now, the test function.

  •  test;⎕USING;ctx;cust;custQuery;orderQuery
     ⎕USING←'' 'Microsoft.Jasper,C:\Programmi\Microsoft Codename Jasper CTP\Binaries\Microsoft.Jasper.CTP.dll'
     ctx←DynamicContext.CreateDynamicContext⊂conn
    ⍝ direct access
     ⎕←{⍵.CategoryName}foreach ctx.Categories
    ⍝ simple query
     ⎕←↑{⍵.(ProductName UnitPrice)}foreach ctx.Products.Where'it.ProductName = ''Chai'''⍬
    ⍝ find by key
     cust←ctx.Customers.FindByKey⊂,⊂'AROUT'
     ⎕←cust.(CustomerID CompanyName)
    ⍝  composite query
     custQuery←ctx.Customers
     custQuery←custQuery.Where'it.Country = ''USA'''⍬
     custQuery←custQuery.OrderBy'it.CompanyName'⍬
     custQuery←custQuery.Select'it.CustomerID, it.CompanyName, it.City'⍬
     ⎕←↑{⍵.(CustomerID CompanyName City)}foreach custQuery
    ⍝ relationship navigation in query
     orderQuery←ctx.Orders.Where'it.Customer.CompanyName = ''Around the Horn'''⍬
     ⎕←↑{⍵.(OrderID OrderDate)}foreach orderQuery

Here's an alternative coding of this test script, based on the simplification offered by Morten's foreach:

  • test1;⎕USING;ctx;cust;custQuery;orderQuery
     ⎕USING←'' 'Microsoft.Jasper,C:\Programmi\Microsoft Codename Jasper CTP\Binaries\Microsoft.Jasper.CTP.dll'
     ctx←DynamicContext.CreateDynamicContext⊂conn
    ⍝ direct access
     ⎕←(⌷ctx.Categories).CategoryName
    ⍝ simple query
     ⎕←↑(⌷ctx.Products.Where'it.ProductName = ''Chai'''⍬).(ProductName UnitPrice)
    ⍝ find by key
     cust←ctx.Customers.FindByKey⊂,⊂'AROUT'
     ⎕←cust.(CustomerID CompanyName)
    ⍝  composite query
     custQuery←ctx.Customers
     custQuery←custQuery.Where'it.Country = ''USA'''⍬
     custQuery←custQuery.OrderBy'it.CompanyName'⍬
     custQuery←custQuery.Select'it.CustomerID, it.CompanyName, it.City'⍬
     ⎕←↑(⌷custQuery).(CustomerID CompanyName City)
    ⍝ relationship navigation in query
     orderQuery←ctx.Orders.Where'it.Customer.CompanyName = ''Around the Horn'''⍬
     ⎕←↑(⌷orderQuery).(OrderID OrderDate)

Easier than writing SQL queries and no need to write any other code except what I listed here. I am amazed.


CategoryTechnologies CategoryDyalogExamplesDotNet

Jasper (last edited 2015-04-05 01:23:20 by PierreGilbert)