Monday, September 24, 2007

XML Literals in VB 9.0

  I usually live in the C# world, have been since 1.0 of the .Net framework. Back then I was interested in VB.Net until the "Don't change VB" crowd started clamoring, at that point I knew that for at least the time being VB.Net would be crippled so I moved on to C#. I've looked at it from time to time since 1.0, but none of it's features has really stood out from the crowd, until now.

  I've spent a great deal of time looking at an experimenting with the .Net 3.5 changes around LINQ and C# and VB.Net are equally matched, with the exception of XML Literals, which is a VB only feature. So what is an XML Literal? Quite simply it's the ability to embed XML directly into your code. Ok, your saying, "I can do this today, so what's the big deal?", the big deal is the XML is a first class object, not a string! In addition to embedding the XML directly in your code, you can also embed expressions in the form of "<%= [exp] %>", which allows you to populate the XML programmatically.

Here's a VB.Net code snippet that populates an XML Literal using an expression to assign the element values:

Public Function PopulateXml(ByVal boundary As Boolean _
                                            , ByVal endPoint As Boolean _
                                            , ByVal vertex As Boolean) As XElement
       Dim snapSettings As XElement = _
       <SnappingOptions>
           <Boundary><%= boundary.ToString() %></Boundary>
           <Endpoint><%= endPoint.ToString() %></Endpoint>
           <Vertex><%= vertex.ToString() %></Vertex>
       </SnappingOptions>

       Return snapSettings
   End Function

 

The code example above returns a LINQ XElement object, the nodes are populated using the expression defined inside the XML.In the end this allows you to produce XML output that matches the original document format and it's embedded right in the code.

 My hats off to the VB team for this little gem, I hope the C# team pays attention and adds it to C# 4.0.

Monday, September 3, 2007

LINQ and Geocoding

Last week had an opportunity to present an overview of LINQ to my coworkers during a brown bag training session. I ran across this article on LINQ and geocoding by Rob Conery, that provides a interesting look at using LINQ to query a to find hotels that a closer than 100 miles.

Friday, August 31, 2007

SQL Server 2008 Date and Time changes

  There are a number of date and time changes coming in the next version of SQL Server 2008 which is currently scheduled for release towards the end of 2007 or early 2008.

 Date and time are now a separate  data types which may make the argument to switch from competing DBMS a little easier. In addition to the new date and time data types, SQL also adds datetimeoffset data type and datetime2 data type.

Here are the highlights of the new data types

Data Type Notes Storage
Date aligns with .Net and SQL Standard data type, supports multiple formats 3 bytes
Time(n) "n" indicates milliseconds precision by default this value is 10 nanoseconds which aligns with windows. 3- 4 bytes
Datetimeoffset(n) Date time offset provides a "time zone aware" data type. date time offset take a parameter that contains the millisecond precision. Time zones from -14:00 to +14:00 are valid  8-10 bytes
datetime2(n) "n" indicates milliseconds precision by default this value is 10 nanoseconds which aligns with windows. 8-10 bytes

 

In addition to adding these new data types SQL Server 2008 also introduces changes in the built in functions, such as GETDATE(), DATEADD() and DATEDIFF() to support these new data types.

The date time changes are welcome additions to SQL server and provide a flexible platform on which to build enterprise applications.

Monday, August 27, 2007

Entity Framework Beta 2 and Tools CTP released

 The ADO.Net Team have released Beta 2 of the Entity Framework an the first Framework Tools CTP.

 You can get the details on the release at the ADO.Net Team Blog

XML Schema Designer

 I just saw that the first CTP for the XML Schema designer is available for download. The designer is a graphical tool for working with XSD schemas, It plugs into Visual Studio, and this CTP only supports VS2008 Beta 2. You can grab it here.

Some interesting LINQ resources

 I ran across Hooked on LINQ today while doing some research for a class I'm putting together for my co-workers on the .Net 3.5 features. It's a well laid out site with a ton of LINQ information, definitely worth a visit. 

 ScottGu's Blog is another great site, as always Scott provides a great deal of insight and examples.

Friday, August 24, 2007

LINQ to DataSets

Erick Thompson has posted an article on LINQ to DataSets. It's a great primer on LINQ querying ADO.Net DataSets.