Visual Studio 2010!

Read now >

View Now
DevSource RSS FEEDS
XML Want an easy way to keep up with breaking tech news? And the Get DevSource headlines delivered to your desktop with RSS.
ADVERTISEMENT
ADVERTISEMENT

 

DevSource.com: Your Source for Visual Studio on Facebook
ADVERTISEMENT
Microsoft Expands .Net With Xen
By Robyn Peterson

Rate This Article: Add This Article To:

Microsoft Expands .Net With Xen - ' Incorporating Relational Data into '
( Page 4 of 6 )

Xen">

Table-like structures can be built in Xen, similar to how classes are created. For example, the following SQL code will construct a table called Customer with each record containing a custid, an integer, and an optional name, a string.

CREATE TABLE Customer
   ( name string NULL,
     custid int);

In Xen, this table could be created with the following line of code:

sequence{ string? name; int custid; }* Customer;

Note: For a definition of 'sequence' or other keywords, skip back two pages to Incorporating XML into Xen.

The collection is made up of a sequence which contains an optional name (string followed by the symbol denoting optional, '?') and an integer custid. The name of the table, Customers, is declared at the end of the line. Notice that the sequence declaration is followed by a '*', that simply means that zero or more sequences can be stored in Customer (in other words, the table can be empty, or may contain any number of records).

Built-In Select Statements
In Xen, you can also write code that performs filtering tasks just like select statements in SQL. Using our just created Customer table, we can retrieve all of the customers who have the name "Fred" and a custid greater than 100.

//Instantiating a Customer table called CustomerTable
Customer CustomerTable;

[Let's assume CustomerTable has some data that was filled in already by a user.]

//Selecting all customers named Fred with a custid greater than 100
Customer* Freds =
      CustTable[it.name=="Fred" && it.custid>100];

For a more complex example, let's use the bibliography we created on the previous page. If we instantiate this object with the name 'bib', we can retrieve all of the books that are published by Addison-Wesley and published after 1991 in the following manner.

book* OldBooks =
      bib.book[it.publisher == "Addison-Wesley" && it.year > 1991];

Note that the implicit variable 'it' is not defined outright, but is understood to be the iterator over all of the books in bib.



 
 
>>> More Microsoft Languages Articles          >>> More By Robyn Peterson