Blogger Widgets
  • Sharing Photos using SignalR
  • TFS Extenstion - allows copy work items between projects
  • Displaying jquery progressbar with ajax call on a modal dialog
  • Managing windows services of a server via a website
  • Exploring technologies available to date. TechCipher is one place that any professional would like to visit, either to get an overview or to have better understanding.

Search This Blog

Monday, 27 February 2012

Assigning default value for fields of type string using Fluent NHibernate

Fluent hibernate provides various decent methods that allow you to map class members with table fields. I have tried using the .Default() method while mapping which works fine for numbers but for string datatype this is not working.

So have looked into the actual execution of sql which looks like (ie.. I have added a new member to the class and want all exists rows to have a default value)

update dept
set location = Manchester

Then I have realised single quote(') were missing for the value which should look like

update dept
set location = 'Manchester'

Now I have updated my mapping as follows

Map(x => x.location).Default("'Manchester'").Not.Nullable();

Never trust anything that can think for itself if you can't see where it keeps its brain.
~J.K. Rowling

1 comments:

Copyright © 2013 Template Doctor . Designed by Malith Madushanka - Cool Blogger Tutorials | Code by CBT | Images by by HQ Wallpapers