LINQ to SQL DataContext and Transactions

17 Sep 2009

I am posting this as a way to remember it, since I am starting a real project using LINQ to SQL soon.

LINQ to SQL orders the objects with pending changes based on their dependencies. LINQ to SQL starts a transaction to wrap the SQL statements. The SQL statements are issued one by one. Any errors detected by the database cause the process to stop and all the changes are rolled back. The DataContext still contains the pending changes enabling you to try and resolve the issue and SubmitChanges again as in this example.

   1: Northwnd db = new Northwnd(@"c:\northwnd.mdf");
   2: // Make changes here. 
   3: try
   4: {
   5:     db.SubmitChanges();
   6: }
   7: catch (ChangeConflictException e)
   8: {
   9:     Console.WriteLine(e.Message);
  10:     // Make some adjustments.
  11:     // ...
  12:     // Try again.
  13:     db.SubmitChanges();
  14: }

Weekend Update

13 Sep 2009

The boy started his art class yesterday so my wife drove him over to it and took the girl along so I had the entire morning to myself. Unfortunately I had to do some work remotely instead of having time to myself. I had to write up a personal performance evaluation. I am not a big fan of doing things like that as it seems to take me forever to write stuff like that.

In the afternoon I went to the bookstore to browse around. It was busier than I have seen it in almost a year. I picked up Neal Stephenson’s Anathem. I haven’t started reading it yet, I mostly picked it up because I had a 30% off coupon.

In the evening we watched the movie Sunshine Cleaning. I thought it would be kind of dark and quirky but it was just depressing. The main character is so pitiful its almost hard to watch. I told my wife we would find something silly to put at the head of the Netflix queue for next weekend.

Styling Alternating Items in ASP.NET MVC Views

8 Sep 2009

Here are a couple of ways to apply styles to alternating items in ASP.NET MVC views.

The jQuery way:

$(’ul > li:nth-child(even)’).addClass(’alt’);
$(’ul > li:first’).addClass(’first’);
$(’ul > li:last’).addClass(’last’);

Rick Strahl’s Odd/Even Looping Method:

<%
    bool oddEven = true;
    foreach (CodeSnippetListItem snip in snippetList)
    {
%>
    <div class="<%= (oddEven = !oddEven) ? "evenclass" : "oddclass" %>">
            Content goes here...
    </div>
<% } %>

jQuery to Highlight the Current Menu Item

4 Sep 2009

Here is a little bit of jQuery code to highlight the current menu item. This presumes you are using a UL > LI > A structure to build your menu.

<script type="text/javascript">
  $(document).ready(function() {
    var path = location.pathname;
  $("li:has(a[href$='" + path + "'])").addClass("selected");  });
</script>

Are all WPF Programs Usability Bad?

3 Sep 2009

I have yet to run to into a usable program written in WPF. I tried another one out this morning and it barely ran. Is there a WPF based application that isn’t a mess?

The most notable WPF program that I have tried is the twitter client blu by thirteen23.com. It seems like the only WPF programs I have come across are twitter clients.

Most of the WPF programs I have tried seem to have the following issues in common that make them unusable for me personally.

  1. There don’t seem to be any keyboard shortcuts which drives me nuts.
  2. The font sizes are to small and the fonts look awful, they are blurry and hard to read.
  3. The interface design is way over the top, yet poorly implement. Interface elements will overlap and don’t layout correctly.

The first and third items in my list seem like they should be blamed on the developers but I have never seen a program developed for another platform with these issues. Number 2 should be blamed on WPF as I believe there is a framework fix for this coming in the next version of .Net.

These problems make me inclined to avoid trying to use anything written in WPF and to certainly avoid trying to develop anything with it.