WPF – LINQ to SQL Sample

This exercise in binding a WPF ListView control with LINQ to SQL was a lot of fun ! The following image shows data from AdventureWorks sample database displayed in the ListView control. The end result is very admirable, even in this very basic demo. Feeling a complete sense of freedom is unavoidable when working with WPF.

Linq2SqlSample1.Png

This sample demonstrates :

  1. LINQ to SQL mapping.
  2. WPF ListView Control DataBinding.
  3. Displaying images stored in database as varbinary in WPF control.

The sample code can be downloaded here : WPF-LINQ to SQL Sample
License : Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.

Creative Commons License

Customize log4net Output Path

The default log4net output path is relative to the startup directory of your executable. To customize the output path, you can override the base Appender’s File property in your own Appender class. The following example describes how to route the log files relative to the temp folder :

   public class MyOwnAppender : log4net.Appender.RollingFileAppender
   {
         public override string File
         {
             get
             {
                 return base.File;
             }

            set
            {
                if (Path.IsPathRooted(value))
                {
                    base.File = value;
                }
                else
                {
                    base.File = Path.Combine(Path.GetTempPath(), value);
                }
            }
        }
    }

Your log4net config file must be modified so that log4net can locate and use your custom Appender. If MyOwnAppender is in MyNamespace and you have implemented it in MyLoggerLib.dll :


Career Advice

The value of any advice is tied to the degree of its relevance to your particular situation and circumstances. Very specific advice, like legal and medical advice, is very expensive. It is very relevant to the individual’s situation and therefore quite valuable. The degree of relevance of inexpensive/free advice to your specific circumstances is usually very low. Inexpensive/free advice, as in sayings and quotes, but also in everyday personal and business communication, is very generic. The same message is usually perceived differently by different people. Especially when the entire message is very succinct and pithy. Various aspects of the message are accentuated differently as it is filtered through individual perception.

  • Developing a sense of how generic advice applies to your individual situation is invaluable.
  • Experience, observation and reading feeds the awareness.
  • Trying and learning from mistakes is essential.
  • Applying the lessons completes the circle.

One of the best career advice I ever got was from reading Spencer Johnson’s Who Moved My Cheese ? The message in this book is timeless. I had been through many significant changes in my life and I think I have handled those changes quite well. After reading this book in 2001, I became consciously aware of the existence of change and my own patterns of behavior and responses to events of change. This awareness has helped me anticipate change, prepare better, make better decisions and handle change more productively.

Database Schema Version Control Tool

It is essential to treat database schema as source code and apply all the norms and best practices applicable to it. From what I hear and read, database schema version control is non-existent in too many projects.

Various techniques to accomplish version control of database schemas have been discussed and published. Martin Fowler and Pramod Sadagale has written a comprehensive article on Evolutionary Database Design. It is a must-read for everyone involved with database development.

K. Scott Allen writes in detail about an excellent system here – Versioning Databases – Change Scripts. This approach is sufficiently light-weight (for my taste) and provides complete control over the whole process.

I am providing a free tool here that you can use to implement this system. It will even create the SchemaVersionsLog table for your database, if it doesn’t exist. If you are using this tool with MSSQL Server, you can get started with very little effort. If you are using a different DBMS, you can still use this tool. It uses NHibernate to access the SchemaVersionsLog table. So, any DBMS supported by NHibernate is acceptable, as long as it comes with a command line tool to execute the sql scripts.

Download DbUpdater here.

Printing Blog Posts

I like printing blog posts and reading them later, but too many blogs don’t provide functionality to print well formatted posts. I end up printing sidebars, advertisements and other clutter along with the post, thanks to lousy print formatting in browsers. What a waste !

It is actually quite easy to add a “Print This Post” button to a WordPress blog. One great option (the one I use on this blog) is WP-Print. Make sure you read Installation and Usage instructions. Brilliant job !

Another option is HP Blog Printing. This works with some other blogging platforms also. I like the simplicity of WP-Print more than the feature set of HP plugin. HP also requires you to sign up.

How do you format posts for printing, when a blog doesn’t have such feature ?