Archive for February 2011

jQuery 1.5 major changes!

February 23, 2011

jQuery team has released their new version with some significant changes. They are all awesome. Here are some quick notes.

1).  Ajax rewrite
“…Perhaps the largest change is that a call to jQuery.ajax (or jQuery.get, jQuery.post, etc.) now returns a jXHR object that provides consistency to the XMLHttpRequest object across platforms (and allows you to perform previously-impossible tasks like aborting JSONP requests)…”

2). Deferred Objects
It’s an wonderful one!
“….This API allows you to work with return values that may not be immediately present (such as the return result from an asynchronous Ajax request). Additionally it gives you the ability to attach multiple event handlers (something that wasn’t previously possible in the Ajax API)….”

3).  jQuery.sub()
“..you could use it to override native jQuery methods without actually affecting the methods that other users would interact with – or even create encapsulated APIs for your plugins that avoid namespace collision…”

5).  Adjacent traversal performance
“…we’ve also been able to improve the performance of some commonly-used traversal methods: .children(), .prev(), and .next()…”

5).  Build system
Using NodeJS, and avoiding the dependency upon Java/Rhino systems
You can get more information about the jQuery 1.5 on their website

 

 

NULL check results differently in LINQ To SQL (L2S) and LINQ To EF (L2E)

February 14, 2011

Here are some interesting gotchas i would like to share that are all confirmed with @jimwooley and @julielerman

As i learnt that L2S & L2E uses different parser to generate the TSQL, thought of checking them mainly with “null” in SELECT & WHERE clause respectively. Surprisingly, i got great differences and listed them here.

LINQ To SQL

I have used Table “Orders” from DB NorthWind

Example: var result = from ord in Orders select ord.ShipRegion;

In SELECT statement

LINQ SQL Equivalent
select ord.ShipRegion ?? “Lara” SELECT COALESCE([t0].[ShipRegion],@p0) AS [value]
select ord.ShipName == null ? “Lara” : ord.ShipName SELECT (CASEWHEN [t0].[ShipName] IS NULL THEN CONVERT(NVarChar(40),@p0) ELSE [t0].[ShipName] END) AS [value]
select Object.Equals(ord.ShipRegion, “Lara”) SELECT (CASEWHEN ([t0].[ShipRegion] IS NOT NULL) AND ([t0].[ShipRegion] = @p0) THEN 1 WHEN NOT (([t0].[ShipRegion] IS NOT NULL) AND ([t0].[ShipRegion] = @p0)) THEN 0 ELSE NULL END) AS [value]
select Object.Equals(ord.ShipRegion, null) SELECT (CASEWHEN [t0].[ShipRegion] IS NULL THEN 1 ELSE 0 END) AS [value]

In WHERE condition

LINQ SQL Equivalent
where Object.Equals(ord.ShipRegion, null) WHERE [t0].[ShipRegion] IS NULL
where Object.Equals(ord.ShipRegion, “Lara”) WHERE ([t0].[ShipRegion] IS NOT NULL) AND ([t0].[ShipRegion] = @p0)
where String.Equals(or.ShipRegion, “Lara”) WHERE ([t0].[ShipRegion] IS NOT NULL) AND ([t0].[ShipRegion] = @p0)
where ord.ShipRegion == (ord.ShipRegion ?? “Lara”) WHERE [t0].[ShipRegion] = (COALESCE([t0].[ShipRegion],@p0))
where ord.ShipRegion == (ord.ShipRegion == null ? “Lara” : ord.ShipRegion) WHERE [t0].[ShipRegion] = ((CASE WHEN [t0].[ShipRegion] IS NULL THEN CONVERT(NVarChar(15),@p0) ELSE [t0].[ShipRegion] END))

Note: DECLARE @p0 NVarChar(1000) = ‘Lara’ Gotchas:

  • ?? => COALESCE()
  • ? => CASE WHEN….END

LINQ To Entity Framework

Used a custom table: Vendor

In SELECT statement

· select (re.VendorName ?? null);
· select (re.VendorName == null ? 
"N/A" : re.VendorName);
SELECT [Extent1].[VendorName] AS [VendorName]
select (re.VendorName.Length > 0 ? 
re.VendorName : "N/A");
SELECT CASE WHEN ((LEN([Extent1].[VendorName])) > 0) THEN [Extent1].[VendorName] ELSE N’N/A’ END AS [C1]

In WHERE condition

DateTime? dt = null; 

where DateTime.Equals(res.UpdatedDateTime, dt)

  • If dt is “null”

WHERE [Extent1].[UpdatedDateTime] IS NULL

  • If dt is “not null”, the following exception for all primitive types:

Unable to cast the type ‘System.Nullable`1’ to type ‘System.Object’. LINQ to Entities only supports casting Entity Data Model primitive types.

String defaultVal = null;

…….

where Object.Equals(re.VendorName, defaultVal)
WHERE [Extent1].[VendorName] = @p__linq__0
· from re in obj.Vendors
  where Object.Equals(re.VendorName, null)
      select re.VendorId;

· from re in obj.Vendors
  where (re.VendorName.Equals(null))
       select re. VendorId;
If we keep “null” directly, then the following weird TSQL for both the LINQ: SELECT CAST(NULL AS int) AS [C1] FROM  ( SELECT 1 AS X ) AS [SingleRowTable1] WHERE 1 = 0
where re.VendorName.Equals(null) || re.VendorId > 0
Consider only VendorId and ignore the other 😦 WHERE [Extent1].[VendorId] > 0
where (!re.VendorName.Equals(null))
Ignores WHERE keyword in TSQL generation 😦
· where (re.UpdatedDateTime == 
(re.UpdatedDateTime ?? dt))

· where (re.UpdatedDateTime == 
(re.UpdatedDateTime == null ? 
dt : re.UpdatedDateTime))
WHERE [Extent1].[UpdatedDateTime] = (CASE WHEN ([Extent1].[UpdatedDateTime] IS NULL) THEN @p__linq__0 ELSE [Extent1].[UpdatedDateTime] END)

Gotchas:

  • For both ?? and ? => CASE WHEN….END in “where” clause only, but ignored in “select” clause
  • Weird TSQL equivalent with .Equals(null)

If anybody has any special thoughts, please comment 🙂

MVC 3 View engine Razor and comparision!

February 7, 2011

Benefits over Razor are

  1. Can be hosted outside ASP.NET
  2. Can unit test views (no need of controller or web-server)
  3. Better intellesense support on VS.NET
  4. Everything is encoded by default
  5. Executing it from a console app is possible
  6. Much cleaner
  7. There’s no need to specify the language, because it’s included in the extension
  8. No need to explicitly specify a master page
  9. No external dependencies as it has been shipped with MVC 3 (System.Web.Mvc.dll)
  10. and lot more

Below are the urls you could enjoy reading over the major 4 view engines, it’s awesome. Just including here as it would help some one over there.

  1. http://channel9.msdn.com/coding4fun/articles/Developer-Review-Four-ASPNET-MVC-View-Engines
  2. http://ironshay.com/post/The-Big-View-Engine-Comparison-e28093-Razor-vs-Spark-vs-NHaml-vs-Web-Forms-View-Engine.aspx

Asp.Net MVC project “The project type is not supported by this installation”

February 7, 2011

One of my team members experienced this issue and was trying all the tricks got from googling, but those are all did not helped him great. After some time, we got a clue from one of the tips and verified System.Web.Mvc version in the project file.

<Reference Include=”System.Web.Mvc, Version=3.0.0.0,…>

We use VS.NET 2010. He had only System.Web.MVC 2.0 installed in his machine but the above entry was showing version 3.0. Then right away we installed MVC 3.0 and tried opening the solution. Wow…it’s worked like a charm.

Hence, if you see System.Web.Mvc Version=2.0.0.0, make sure you have MVC 2.0 installed. Likewise if see Version=3.0.0.0, make sure MVC 3.0 installed. That’s it  🙂

 

Which came first? Egg or Chicken!

February 6, 2011

The winner is “Chicken”! 🙂

Find below the excerpt from the link http://www.wibw.com/internationalnews/headlines/98420064.html

It was a world first and revealed that the true purpose of the protein ovocledidin-17 is to speed up the production of eggshell within the chicken so that in 24 hours an egg is ready to be laid.

“What we have really identified is that the protein seems to accelerate the crystallization process so it can make that eggshell appear far quicker. In simple terms it accelerates calcite formation,” Freeman said.

They also found that the egg can’t be produced without the protein ovocledidin-17 in the chicken’s ovaries, so that means that the chicken must have come first. Right?

One more link about the same.

http://whyevolutionistrue.wordpress.com/2010/07/14/godawful-science-reporting-msnbc-says-the-chicken-came-before-the-egg/

Finally, science is the real master here!

ASP.NET MVC 3 & New view engine “Razor”!

February 6, 2011

Most of you must have heard about MVC 3 has been released few months ago with the big bang! It has come up with too many features and improvement. Thought of giving some quick info and links related to that.

Find below the link from Scottgu depicting about the same. Excellent one!

http://weblogs.asp.net/scottgu/archive/2010/11/09/announcing-the-asp-net-mvc-3-release-candidate.aspx


Top features:

  • New view engine called “Razor” with much simplified
  • Support for Multiple View Engines
  • Powerful hooks with Dependency Injection and Global Action Filters
  • Rich JavaScript support with unobtrusive JavaScript, jQuery Validation, and JSON binding
  • Streamlined validation with improved Model validation

Here is the pointer over Razor:

http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx


Web form Vs Razor syntaxt comparision and example from haacked.com, i loved this very much 🙂

http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx

One more interesting part, yes..there is a tool you can convert WebForms(asp.net) Views to Razor (C# Only). Actually it was developed by the Telerik ASP.NET MVC team for internal use, but now it is available free over GitHub.com.

Here you go….https://github.com/telerik/razor-converter. There are some limitations with this tool, check it out there.

Enjoy playing with MVC 3!