Thursday, September 22, 2011

Windows 8 - Pre-beta version for developers

Windows 8 pre-beta version for developers is available for download on Microsoft website.


The installable can be downloaded using the following link:-


http://msdn.microsoft.com/en-us/windows/apps/br229516


Hopefully Windows 8 will be as successful as Windows XP is.



New features in the .NET Framework 4.5 Developer Preview


I was going through Microsoft MSDN website and found that .Net Framework 4.5 developer preview is available as BETA version. 

Following are some of the features available in .Net Framework 4.5:-


Web:

• Support for new HTML5 form types.
• Support for model binders in Web Forms. These let you bind data 
  controls directly to data-access methods, and automatically 
  convert user input to and from .NET Framework data types.
• Improved handling of client script through bundling and 
  minification for improved page performance.
• Support for reading and writing HTTP requests and responses 
  asynchronously.
• Support for asynchronous modules and handlers.


WPF:

• The new Ribbon control, which enables you to implement a ribbon 
  user interface that hosts a Quick Access Toolbar, Application 
  Menu, and tabs.
• The new INotifyDataErrorInfo, which supports synchronous and 
  asynchronous data validation.
• Improved performance when displaying large sets of grouped 
  data, and by accessing collections on non-UI threads.
• Repositioning of data as the values change (live shaping).
• Better integration between WPF and Win32 user interface 
  components.
• Ability to set the amount of time that should elapse between 
  property changes and data source updates.


WCF:

• Simplification of generated configuration files.
• Support for contract-first development.
• Ability to configure ASP.NET compatibility mode more easily.
• Changes in default transport property values to reduce the 
  likelihood that you will have to set them.
• Validation of WCF configuration files by Visual Studio as part 
  of the build process, so you can detect configuration errors 
  before you run your application.
• New HTTPS protocol mapping to make it easier to expose an 
  endpoint over HTTPS with Internet Information Services (IIS).
• Ability to generate metadata in a single WSDL document by 
  appending ?singleWSDL to the service URL.
• Support for configuring services in code.
• XML Editor tooltips.


The description of these added features are not provided on the website. After installation and usage of new beta version of VS 2011 will give a idea about these new features.

Wednesday, September 21, 2011

Converting xml document data into a table rowset view in SQL server

OPENXML:-

OPENXML provides a rowset view over an XML document.

Syntax 

OPENXML(idoc int [in],rowpattern nvarchar[in],[flags byte[in]]) 
[WITH (SchemaDeclaration | TableName)]



sp_xml_preparedocument:-

Reads the XML text provided as input, parses the text by using the MSXML parser (Msxmlsql.dll), and provides the parsed document in a state ready for consumption. sp_xml_preparedocument limits the number of elements that can be open at one time to 256.
Syntax 
sp_xml_preparedocument
hdoc 
OUTPUT
[ , xmltext ]
[ , xpath_namespaces ] 

This example creates an internal representation of the XML image using sp_xml_preparedocument. A SELECT statement using an OPENXML rowset provider is then executed against the internal representation of the XML document.

DECLARE @BookDetails xml

DECLARE @handle INT

SET @BookDetails =

'<Books>
                  <Book>
                        <author_id>1</author_id>
                        <author_fname>Stephen</author_fname>
                        <author_lname>Smith</author_lname>
                        <book_title>Dotnet reference</book_title>
                        <price>30.50$</price>
                  </Book>
                  <Book>
                        <author_id>2</author_id>
                        <author_fname>John</author_fname>
                        <author_lname>Arthor</author_lname>
            <book_title>Donet complete review</book_title>
                        <price>35.50$</price>
                  </Book>
             </Books>'

EXEC sp_xml_preparedocument @handle OUTPUT, @BookDetails   
SELECT * FROM OPENXML (@handle, '/Books/Book', 2) WITH
  (author_id VARCHAR(5),
   author_fname NVARCHAR(500),
   author_lname NVARCHAR(500),
   book_title NVARCHAR(100),
   price nvarchar(10)  
  )

Output:-
author_id  author_fname   author_lname  book_title              Price  

1          Stephen        Smith         Dotnet reference        30.50$

2          John           Arthor        Donet complete review   35.50$


The OPENXML rowset provider creates a five-column rowset (author_id, author_fname, author_lname, book_title and price) from which the SELECT statement retrieves the all the necessary columns.

The flag value is set to 2 indicating attribute-centric mapping. Therefore, the XML attributes map to the columns in the rowset. The rowpattern specified as /Books/Book identifies the <Books> nodes to be processed.

If the same SELECT statement is executed with flags set to any value other than 2, indicating element-centric mapping, the values of author_id, author_fname, author_lname, book_title and price for both of the book records in the XML document are returned as NULL.



Tuesday, September 20, 2011

Table row generation based on two date difference


Recently i faced a situation where i was supposed to generate a table records based on the difference of two date parameter values.


After searching a lot on internet, i came up with a solution to my problem using Common Table expression feature of SQL server.


MSDN definition states:- 
A common table expression (CTE) can be thought of as a temporary result set that is defined within the execution scope of a 
single SELECT, INSERT, UPDATE, DELETE, or CREATE VIEW statement. A CTE is similar to a derived table in that it is not stored as an object and lasts only for the duration of the query. 
Unlike a derived table, a CTE can be self-referencing and 
can be referenced multiple times in the same query.


The query example for generating the table:-


BEGIN
     Declare @FromDate as DateTime
     Declare @ToDate as DateTime   
     Set @FromDate = cast('09/01/2011' as datetime)
     Set @ToDate = cast('09/15/2011' as datetime)

     ;With cteTemp as (
               select 1 i, @FromDate As FromDate
               Union All
               select i+1, DateAdd(Day,i,@FromDate) 
               From cteTemp
               Where DateAdd(Day,i,@FromDate)&lt;=@ToDate 
         )   
       select * from cteTemp
END


Above mentioned query generates 15 records based on the difference between the date values. As Common table expression works in recursive way, same table name is used inside the query for looping purpose.

LINQ queries


LINQ popularly known as Language Integrated Query. LINQ language is one of the major advancement in .Net framework and is used for writing type-safe queries over object collections. LINQ was introduced in C# 3.0 and Framework 3.5.



In simple terms a basic unit of data in LINQ are called as sequence and elements.
Following example can explain these terms:


string[] place = { "Bangalore", "Pune", "Mumbai" };


In the above example, place is a sequence,and Bangalore, Pune and Mumbai are elements.


In the System.Linq class, there are around 40 query operators which are implemented as static extension methods.A query operator accepts an input sequence and generates output sequence.


For example:- Where operator can be used to extract cities with at least four characters length


string[] place = { "Bangalore", "Pune", "Mumbai" };
IEnumerable filteredPlace = place.Where(n=&gt; n.Length&gt;=4);


Output:-
Bangalore
Mumbai