TJ's Blog TJ's Blog on .NET and Programming

Data Pager Load Error

May 26

If you are using a data pager on your view in a Silverlight application, when you run it and try to click the next page button couple of times you may get an error like this:

DataPager Error

This is because the query is stateless and without an order, it is not possible to do a valid skip.

So, for the datapager to work correctly, you need to provide an “order by” to your returned resultset.

Assuming that you are using DomainServices, go to your domain service and find the Get() method. This could be GetCustomers, GetOrders etc.

The code you will see is something like below:

 public  IQueryable <Customers > GetCustomers()
 {
     return  this .ObjectContext.Customers;
 }

Change this to:

 public  IQueryable <Customers > GetCustomers()
 {
     return  this .ObjectContext.Customers.OrderBy(c => c.CustomerID);
 }

And you have your data pager working nicely.

Firefox Cache Problem When Debugging Silverlight Apps

May 25

On a previous article, we looked at how we can change the default browser that we use to run our Silverlight application in Visual Studio.

You can definitely choose Firefox as your default browser, however, you need to be aware that if you close the tab or the browser while your Silverlight application is running, your debugging session will not end. The same applies to when you end your debugging sessions from Visual Studio – you will see that the tab or the browser does not close. You do get this behavior for free in Internet Explorer.

But the biggest difference between debugging a Silverlight application in Firefox and Internet Explorer is the cache. With Firefox, sooner or later you will see that the browser will not be loading the latest build every time you run your app. Firefox keeps feeding you the cached version. Of course, you can put a version number to you xap files but as you can imagine this gets very inefficient when you are developing a Silverlight application.

There is a plug-in in Firefox, called Web Developer (http://chrispederick.com/work/web-developer/). After installing this plug in, just disable the cache by right clicking on a web page and choosing Disable >> Cache from the menu and you should be good to go.

Figure: Using Disable menu option in Firefox plug in Web Developer.

Another option you have is getting Firefox in Private Browsing mode.  This mode, does not record anything about your session, so it should load the latest build of your Silverlight application. You can start a private session from Tools >> Start Private Session.

Figure: Starting a private session in Firefox

Internet Explorer, however, does not seem to have this problem.

Northwind for the Masses

May 24

Northwind is an old database (coming from the MS Access days) that stood the test of time. It is a simple, lightweight database that is great for proof of concepts, working prototypes, demos and presentations. However, the new SQL Server versions do not install Northwind as a sample database on your computer. So unless you have a Northwind.mdb somewhere and want to upsize that database, you do not have access to this database.

Well, there is still hope. Microsoft has Northwind and pubs database available for SQL Server 2000 at this address: http://www.microsoft.com/downloads/details.aspx?familyid=06616212-0356-46a0-8da2-eebc53a68034&displaylang=en

Once you download the setup program and run it, you will see that a folder named “SQL Server 2000 Sample Databases” is created on your c:\ drive. If you go to that folder, you will see Northwind and pubs databases. You can either attach the .mdf files in SSMS or run the SQL scripts.

Additionally, codeplex has a SQL Server product page that has all the samples for lot of different database versions. It may be worth checking out: http://sqlserversamples.codeplex.com/

On top of that, there is an initiative for “Northwind Community Edition”. This initiative aims to extend the Northwind database and bring it to 2010 (from 1990’s). There does not seem to be much activity in the project lately, but if you want to check it out, here is the address: http://northwindcommunity.codeplex.com/