NHibernate Query Generator

I finally took the time today to get NHibernate Query Generator running in my project.  I should have done this a long time ago!

NHQG makes querying more intuitive then the Criteria.

Ayende is the creator – here is one link that show him introducing version 1.5 (I’m using 1.8)

You can download it here

To integrate with VS 2008, there is a registry key needed you can get here (thank you Ryan Cromwell!).   Ryan has a link here and here (I did this one, not the first one – but I will look into it) about installing and using it.

Last link for the topic – building up a dynamic query with the NHQG QueryBuilder

I used this with my Spring.NET/NHibernate Dao classes fairly easy.  My base class would have something like ‘FindAll(DetachedCriteria criteria, Order order)’

So, my query is something like this then:

List<Person> people = PersonDao.FindAll(Where.Person.FirstName == ‘Steve’, OrderBy.Person.LastName);

It supports ‘Where’, ‘Group’ ‘Projection’ and ‘OrderBy’.  You build up the queries just like OO collection building (similiar perhaps to Linq).

Where.Person.FirstName.InSensitiveLike(‘eve’, MatchMode.StartsWith);

Advertisements

ASP.NET MVC Source Refresh Preview

Scott Guthrie has posted on update on asp.net mvc, outlining some new features and upcoming changes…

The testing with the ActionResult on the action looks good.  I also noticed they internally use Moq to do their mocking.  Moq is very slick!  What is really good to see is that this framework is being built with testing in mind.  That is a big deal that shouldn’t be overlooked or brushed off lightly.  Very refreshing !

Other changes include empty ‘RenderView’ calls that default to the action’s name (Monorail did this).

Other items include the new MapRoute helper, which support characters in the url (this should help in the senario I had where I was using ‘gamertags’ that were sometimes problematic, ie. 4./Jg53_Recon -> the url didn’t like this too much  šŸ™‚

“Note that in addition to using the new routing system for ASP.NET MVC scenarios, we are also now using the same routing system within ASP.NET Dynamic Data (which uses ASP.NET Web Forms).”

I haven’t used the ‘RouteLink’ html helper, but it looks powerful and Scott includes a sample on this as well.

I will most likely wait for the preview 3 drop, but it’s good to see what is coming down the road (I also wonder how many ‘preview’ numbers we’ll have – lol)

Big thanks to Mr. Gu for this update!

Update 1: In the comments section:

>>>>>> Will this new official preview version 3, support dynamic languages.

Dynamic language and DRL support is coming.  Expect more samples on this soon.

Update 2: Walkthrough of using pre-Preview 3 By Fredrik Normen (great blog site by the way)

This walkthrough highlights some of the changes that Scott mentioned:

MS MVC – jQuery Ajax’d Forms

First, check out the link to the form quickstart: http://malsup.com/jquery/form/

Within my MS MVC control I have the following:

<form id="frmAddEmployeePlan" action="/Employee/SaveEmployeePlan" method="post"> 
<%= Html.TextBox("CompanyContributionAmount", "")%>
<input type="submit" value="Save" /> 
 

That is the form.  I kept it simple for the demo.

Note the action – this is key – I’m sending it to the Employee controller’s ‘SaveEmployeePlan’ action.

 

At the top of this form I have the following javascript to wire up the ajax form:

<script type="text/javascript">
$(function(){
        
    $('#frmAddEmployeePlan').ajaxForm(function() { 
                alert("Thank you for your comment!"); 
            });
            
    
   });
 

This is fairly straight forward jQuery stuff.  Basically it intercepts the form request, makes it an ajax call.

Now in my SaveEmployeePlan:

public void SaveEmployeePlan()
        {
            string test = this.ReadFromRequest("CompanyContributionAmount");
        }

I read the request in just to validate it works  – works great.

Very simple example, I would use some of the options here: http://malsup.com/jquery/form/#code-samples

ie. in their example it shows this:

// prepare the form when the DOM is ready $(document).ready(function() { var options = { target: '#output1', // target element(s) to be updated with server response beforeSubmit: showRequest, // pre-submit callback success: showResponse // post-submit callback // other available options: //url: url // override for form's 'action' attribute //type: type // 'get' or 'post', override for form's 'method' attribute //dataType: null // 'xml', 'script', or 'json' (expected server response type) //clearForm: true // clear all form fields after successful submit //resetForm: true // reset the form after successful submit // $.ajax options can be used here too, for example: //timeout: 3000 }; // bind form using 'ajaxForm' $('#myForm1').ajaxForm(options); });

 

The target here is key.  So on my form I would setup a div with an id of ‘output1’ and write the ‘thank you’ into that div and then use the ‘clearForm : true’

ie.

public void SaveEmployeePlan()
        {
            //collect form data and save it
            Response.Write("Thank you");
        }

Slick eh?

MS MVC – jQuery Ajax'd Forms

First, check out the link to the form quickstart: http://malsup.com/jquery/form/

Within my MS MVC control I have the following:

<form id="frmAddEmployeePlan" action="/Employee/SaveEmployeePlan" method="post">
<%= Html.TextBox("CompanyContributionAmount", "")%>
<input type="submit" value="Save" /> 
 

That is the form.  I kept it simple for the demo.

Note the action – this is key – I’m sending it to the Employee controller’s ‘SaveEmployeePlan’ action.

 

At the top of this form I have the following javascript to wire up the ajax form:

<script type="text/javascript">
$(function(){

    $('#frmAddEmployeePlan').ajaxForm(function() {
                alert("Thank you for your comment!");
            });


   });
 

This is fairly straight forward jQuery stuff.  Basically it intercepts the form request, makes it an ajax call.

Now in my SaveEmployeePlan:

public void SaveEmployeePlan()
        {
            string test = this.ReadFromRequest("CompanyContributionAmount");
        }

I read the request in just to validate it works  – works great.

Very simple example, I would use some of the options here: http://malsup.com/jquery/form/#code-samples

ie. in their example it shows this:

// prepare the form when the DOM is ready $(document).ready(function() { var options = { target: '#output1', // target element(s) to be updated with server response beforeSubmit: showRequest, // pre-submit callback success: showResponse // post-submit callback // other available options: //url: url // override for form's 'action' attribute //type: type // 'get' or 'post', override for form's 'method' attribute //dataType: null // 'xml', 'script', or 'json' (expected server response type) //clearForm: true // clear all form fields after successful submit //resetForm: true // reset the form after successful submit // $.ajax options can be used here too, for example: //timeout: 3000 }; // bind form using 'ajaxForm' $('#myForm1').ajaxForm(options); });

 

The target here is key.  So on my form I would setup a div with an id of ‘output1’ and write the ‘thank you’ into that div and then use the ‘clearForm : true’

ie.

public void SaveEmployeePlan()
        {
            //collect form data and save it
            Response.Write("Thank you");
        }

Slick eh?

Posting comments and WordPress Themes

I’ve switched back to more of an original wordpress theme, it appears the one I was using has problems with comments.

I know the problem with the default is that the text runs off to the right, so I’ll have to investigate that next.

So, you might see the themes change as I experiment with WordPress  šŸ™‚

Thanks