Labels

Friday, October 30, 2009

XML & DTD

Hi

 

Here the left is XML and right one is it’s DTD to validate the left side XML.

 

XML

DTD

<xml version="1.0"?>

 

<po id="PO1456">

 

  <date year="2002" month="6" day="14" />

 

  <address type="shipping">

    <name>Frits Mendels</name>

    <street>152 Cherry St</street>

    <city>San Francisco</city>

    <state>CA</state>

    <zip>94045</zip>

  </address>

 

  <address type="billing">

    <name>Frits Mendels</name>

    <street>PO Box 6789</street>

    <city>San Francisco</city>

    <state>CA</state>

    <zip>94123-6798</zip>

  </address>

 

  <items>

    <item quantity="1"

          productCode="R-273"

          description="14.4 Volt Cordless Drill"

          unitCost="189.95" />

    <item quantity="1"

          productCode="1632S"

          description="12 Piece Drill Bit Set"

          unitCost="14.95" />

  </items>

</po>

<?xml version="1.0" encoding="UTF-8"?>

 

<!ELEMENT po (date,address+,items)>

<!ATTLIST  po id CDATA #REQUIRED>

 

<!ELEMENT date EMPTY>

<!ATTLIST date year CDATA #REQUIRED

               month (1|2|3|4|5|6|7|8|9|10|11|12) #REQUIRED

               day (1|2|3|4|5|6|7|8|9|10|11|

                    12|13|14|15|16|17|18|19|

                    20|21|22|23|24|25|26|27|

                    28|29|30|31) #REQUIRED>

 

<!ELEMENT address (name,company?,street+,city,state,zip)>

<!ATTLIST address type (billing|shipping) #REQUIRED>

<!ELEMENT name    (#PCDATA)>

<!ELEMENT company (#PCDATA)>

<!ELEMENT street  (#PCDATA)>

<!ELEMENT city    (#PCDATA)>

<!ELEMENT state   (#PCDATA)>

<!ELEMENT zip     (#PCDATA)>

 

<!ELEMENT items (item)+>

 

<!ELEMENT item EMPTY>

<!ATTLIST item quantity CDATA #REQUIRED

               productCode CDATA #REQUIRED

               description CDATA #REQUIRED

               unitCost CDATA #REQUIRED>

 

 

Thanks & Regards,

Arun Manglick || Senior Tech Lead

 

 

The NOT IN clause in LINQ to SQL

The NOT IN clause in LINQ to SQL

 

Programmers used to write SQL queries often want to know a LINQ syntax equivalent to the SELECT NOT IN clause in SQL.

Consider this code that returns all the customers who don't have an order in the Orders table. This is one SQL query that returns that value.

 

SELECT *
FROM [dbo].[Customers] AS [t0]
WHERE [t0].[CustomerID] NOT IN (
    SELECT [t1].[CustomerID]
    FROM [dbo].[Orders] AS [t1]
)

 

This is not the faster way to get the desired result (using a NOT EXISTS is the favorite way - more on this shortly). LINQ offers a Contains extension method that allows writing the following code.

 

NorthwindDataContext dc = new NorthwindDataContext();

dc.Log = Console.Out;

var query =

    from c in dc.Customers

    where !(from o in dc.Orders

            select o.CustomerID)

           .Contains(c.CustomerID)

    select c;

foreach (var c in query) Console.WriteLine( c );

 

In LINQ to SQL the query is translated into this SQL code:

 

SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName],

       [t0].[ContactTitle], [t0].[Address], [t0].[City],

       [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[Phone], [t0].[Fax]

FROM [dbo].[Customers] AS [t0]

WHERE NOT (EXISTS(

    SELECT NULL AS [EMPTY]

    FROM [dbo].[Orders] AS [t1]

    WHERE [t1].[CustomerID] = [t0].[CustomerID]

    ))

 

This approach is not only semantically equivalent, but also faster in execution. The following is the result with SET STATISTICS IO ON. The first result is for the hand-written query that use the NOT IN clause.  The second result is for the LINQ to SQL generated query.

 

(2 row(s) affected)

Table 'Orders'. Scan count 182, logical reads 364, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

Table 'Customers'. Scan count 1, logical reads 5, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

 

(2 row(s) affected)

Table 'Orders'. Scan count 1, logical reads 5, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

Table 'Customers'. Scan count 1, logical reads 5, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

 

The LINQ query is not always similar to SQL (like from/select), but in general you should be able to write in LINQ a SQL query. However, there is not always a direct translation for each single SQL keyword, but you can get the same result with semantically equivalent statements.

 

 

Thanks & Regards,

Arun Manglick || Senior Tech Lead

 

 

Tuesday, October 6, 2009

Building Cascading DropDownList in ASP.Net Using jQuery and JSON

Hi,

 

Recently worked for ‘Building Cascading DropDownList in ASP.Net Using jQuery and JSON’.

Reference: Link

 

The reason to go for this approach is the problem while using Cascading DropDown in Update Panel.

Here is the Link, Link, Link

 

However as I had thought, the soultion is not promising with Jquery & JSON as well. i.e it Things works fine till the records are less than 1000 (1k).

It dies when the count reaches to 5k & becomes worst at 10k.

Here is where the solution and the problem - Link

 

Hope this helps.

 

Thanks & Regards,

Arun Manglick || Senior Tech Lead