Archives

Archives / 2008 / March
  • Update to my LINQ to SQL performance in VB.NET saga

    Hello,

    If you have  read my posts before where I was complaining about VB generated sub optimal SQL when using nullable columns in your where clauses, I came to the conclusion I was being silly and not using .Value on those nullable fields in my queries.

    I stumbled across this post today:

    http://blogs.msdn.com/vbteam/archive/2008/03/28/linq-to-sql-and-linq-to-entities-performance-improvements-tim-ng.aspx


    Looks like it was an issue in the end and not me being totally stupid :).

  • Book Review: Linq Quickly by N Satheesh Kumar

    This books title does not lie, it is LINQ and it is quickly. This book is an excellent introduction into the world of LINQ and also a great reference once you get your feet wet.

    The start of the book gives you a brief introduction into what LINQ is and also an introduction into the new features in C# 3.0. It covers things like anonyms types, object initializers, collection initializers, partial methods, implicitly typed local variables, extension methods, lambda expressions,  query expressions and also a small intro to expression trees.

    Then it covers LINQ to Objects, which gives you a good idea on how to use LINQ over your in memory objects, including arrays, collections, string and even text files. It shows you just how easy it is to do things that in the past would have been a lot harder to complete.

    Next up is LINQ to XML, this is a great introduction to this subject, it covers a great deal of information in regards to all the new LINQ to XML classes, how to create/update/delete XML documents using these new classes and methods. You are also shown the power you now have when you are querying XML and how easy it just is.

    The LINQ to SQL chapter is also an excellent reference if you would like to get your feet wet but would not like to be overwhelmed with information. There are plenty of good examples on how to begin using LINQ to SQL and the code samples provided make this very easy. It covers everything from Data Context, Attributes, Relationships, querying, data manipulation, using stored procedures and also all the other common query operators that you would use. There is also a chapter on LINQ to Datasets but as I never use datasets this was something I briefly skimmed over and did not digest.

    Finally the book provides a good chapter on Standard Query Operators, this is an excellent post reference once you are already in the world of LINQ, it is good to able to flick to be back, find what you need and see the function prototypes and even a code sample on how to use it. I still sometimes will flick to this part of the book to quickly reference things when I forget :P.

    All in all this was an excellent book and I would highly recommend it to anyone who would like to start out with LINQ but would like to get a quick introduction and be on their way to actually using it. This book provides just that and more


    Book Information:

  • A Templated ASP.NET RSS Feed Reader Control

    Update 20070330:

    By popular demand (well a couple people) I have included a sample project with everything needed to get started using this control.

    Basically just a sample web project, click here to get the zipped archive. You might notice things are done a little different, I include the System.ServiceModel.Syndication namespace on my page so that I can case the Container.DataItem to a SyndicationItem and access its properties that way, stops using Eval, but each to their own.


    Hope that makes it easier for some, will be including full source in future too :).

    Project Files:
    TemplatedRSSFeedReader.zip

    Thanks
    Stefan


    Update 20070319:

    Today I attended the Heros Happen event in Perth, and I learnt something very very cool, you see how I wrote my own classes and code to load the syndicated feed in, then used LINQ to XML to load that into my classes. During Dave Glovers presentation on WCF he had a sample in there that was building an RSS feed, and I could see he was using some classes to do so. What I then noticed is these classes are new in .NET 3.5 and will make creation of this control 100 times easier plug give us full support of the RSS 2.0 spec and allow us to access all feed proprties :) :) and will mean *removing* code and making things much simpler.

    Firstly we need to add a reference to the System.ServiceModel.Web assembley, this is where the magic is. Then add a using System.ServiceModel.Syndication; to the RSSReader.cs class, we then have access to these helper classes which allow us to easily read and create RSS 2.0 and ATOM 1.0 feeds, as I am only supporting RSS I will only use the RSS formatter. To read our feed we need to do the below:

    Firslty read the feed into an XMLReader:

    XmlReader reader = XmlReader.Create("http://weblogs.asp.net/stefansedich/rss.aspx");

    Then create an instance of the RSS20FeedFormatter and then make this read the data from the xmlreader:

    Rss20FeedFormatter feedFormatter = new Rss20FeedFormatter();
    feedFormatter.ReadFrom(reader);


    We now can get access to the feed by using feedFormatter.Feed, this gives us an instance of a SyndicationFeed class which gives us access to all items and properties of our feed. The only difference now is that as some properties are a little different accessing them is different.So instead of feed.Title you use feed.Title.Text instead. The good thing with this is, 1. We have removed the need to do this manually and 2. We have all properties that belong to an RSS feed.

    The updated RSSReader class is below with the code changes. You can now remove the Feed and FeedItem classes we created earlier as they are needed no more. It just goes to show we learn something new every day.....


    Code:

  • ASP.NET Ajax using a custom ViewManager to render paged data without updatepanels

    Sometimes you do not want the overhead of using an updatepanel, as each time you make a request it is posting more back than you might need, sure it can be powerful and easy to use but not always the most effective way Say you would like to be able to not use viewstate or postbacks but would like to get a result set of data that can be paged and you would like this totally client driven and to use the least ammount of overhead.

    Following on from Scott Guthries ViewManager (thanks Scott), and some ideas I have had lately to do alot more things client side and maybe stop using updatepanels. I have made a more generic ViewManager which I blogged about earlier, basically is just allows you to set properties of your control alot easier and can set any properties the control may have before you go ahead and render it. Don't flame for writing something already done, I find my version of the ViewManager easier to use, so thought I would share.