Posts

Linq To SQL and Change Tracking

I have been using Linq To SQL in a project recently. Linq is a great way to traverse through a collection of objects. Its a very nice utility and can get rid of those unsightly nested foreach loops with if/elses in your code. Linq To SQL is also a nice basic Object Relational Mapper. The issue is "when the rubber meets the road", as it were. Linq seems a slight bit incomplete. Take this example: A simple ChangeLog class. It has an Enum ChangeLogStates that has 4 states, Created, Modified, StatusChanged (a disposition), Shelved(basically deleted). Now, i could do an ChangeLog.add(LogStates.Created/Modified/Changed/Shelved,Object Key, strDescription) to every line of code where there is a change in the database....everywhere i insert, update the underlying entity. But Using the beauty of OOP and Linq to SQL, i can impletement the Datacontext's insert and update partial methods: partial void insertLinqItem(LinqItem item); partial void updateLinqItem(LinqItem item); in...

The Infamous "Clear All Controls" , Generics Style

In the ASP.NET world, its invaluable to be able to clear all controls on a form, or disable all controls, or even reset the controls to a default state. I am going to show you an awesome way to do it, Generics Style. We will be building this using a method that takes in a Generic Type of Control, and a /// /// Excellent Method to abstract and add into the Helper classes : Using Generics /// /// private void ManageControls (Control parent, Func del) where Gen : Control { foreach (Gen c in parent.Controls) { if (c is Gen) { del.Invoke(c); if (((Control)c).HasControls()) ManageControls (((Control)c), del); } } } ManageControls (parent, x => x.Items.Clear()); ManageControls (parent, x => x.Text = "");

Fix for the 500 Internal Server Error after the upgrade to Rails 2.0.1

After trying to find an answer, i found one at http://weblog.rubyonrails.org/2007/12/7/rails-2-0-it-s-done from blog comment #83. Apparently there is a need to seed the session key in the session, with a 30+ character string. In your config/enviornment.rb within the Rails::Initializer.run do |config| / end block add the following: config.action_controller.session = { :session_key => "_myapp_session", :secret => "Any 30+ character string will do here, so choose whatever"} Hope this helps. Enjoy Rails 2.0+