Archive for the ‘NHibernate’ category

New NHibernate.Linq – to be part of NHibernate assembly

March 18th, 2010

Steve Strong has posted an update:

http://nhforge.org/blogs/nhibernate/archive/2009/12/17/using-the-new-linq-to-nh-provider-and-migrating-from-the-old-one.aspx

It is in the trunk now:

http://nhibernate.svn.sourceforge.net/viewvc/nhibernate/trunk/nhibernate/src/NHibernate/Linq/

Learn more about this provider here:

http://nhforge.org/blogs/nhibernate/archive/2009/12/17/linq-to-nhibernate-progress-report-a-christmas-gift.aspx

 

Sorry for not much detail besides the links, but this is pretty big news for Linq and NHibernate.  I have been reading progress reports from Steve for quite awhile now – saw some code in a trunk ~4 months ago that looked very promising then, so it’s great to see these updates.  Awhile back Ayende posted on EF vs. NH, etc… and two things popped out: good Linq support and a good GUI to creating mapping files.  I think this is the Linq support we have been waiting for.

Fantastic Friday – Links, thoughts and more…!

December 4th, 2009

Happy Friday to you  :)   I’m looking forward to my employer’s (Strategic Data Systems) Christmas party tommorow night.  It’s always a fun time.

SquareUp by Twitter

http://squareup.com/
Twitter founder formally unveils ‘Square’ project  – this is pretty cool I think – the ability to have “mobile-payments”.  

Here is a description:

The Square hardware is a small, inexpensive card reader that plugs into the audio jack of a compatible device, including a mobile phone (it’s starting with the iPhone and currently has job postings up for BlackBerry and Android engineers). It processes credit card payments, geotags their locations on a map, and e-mails a receipt to the buyer.

I think it’s a great idea – pretty cool stuff. 

Visual NHibernate Beta

At first I thought this might be ‘free’  :)   But it’s not.  However, I must say, it’s looking very nice.  Based on some NH google lists the developer(s) are very responsive to adding features and bug fixes.  That was good to see.  One of the ‘complaints’ that I hear sometimes about NHibernate (vs. like EF, L2S, or commercial ORMs) is that it’s complex to get up and running if your not familiar with how mapping files, etc… work.   So Visual NHibernate provides a visual designer and mapping tool for creating and editing NHibernate projects.

Ryan Cromwell – Castle Windsor

Not sure if I blogged on this before (yeah… I know I can search…) but I really like working with Castle Windsor’s Inversion of control container.  Ryan Cromwell (fellow contractor at Strategic Data Systems) provides a couple of good blog posts on it’s usage.  I was recently asked about factory facility for Windsor, and I was able to refer that person to Ryan’s post (see ‘Injecting WCF Channel as Dependency..’ below)

Strategy Pattern with Castle Windsor (he includes a sample project – thanks Ryan!)

Registering WPF “Views” with Windsor Fluent API

Injecting a WCF Channel as Dependency via Windsor – this shows off the Factory facility for Windsor.

By the way – a plug for Ryan:  He is our TFS specialist and can help setup, provide guidance, etc… for TFS.  If your looking for someone to do that for you – he is definitely the man to get!  I should add, he is a heck of a WPF programmer as well – he does some really fine work!

MVC Turbine – Plugin for ASP.NET MVC

http://mvcturbine.codeplex.com/

From CodePlex:

MVC Turbine is a plugin for ASP.NET MVC that has IoC baked in and auto-wires controllers, binders, view engines, http modules, etc. that reside within your application. Thus you worry more about what your application should do, rather than how it should do it.

This is very good to see from my perspective.  One of the features I really enjoyed while experimenting with Grails was how easy it was to have everything injected under the covers without needing to get into the weeds (in Grails case – Spring).  MVC Turbine offers this same functionality for the ASP.NET MVC programming.

Turbine is not exclusive to a particular IoC container.  Here is a feature list:

Features

  • Visual Studio 2008 Solution Templates for IoCs
    • Ninject
    • Castle Windsor
    • StructureMap
    • Unity
  • New runtime framework that allows extensibility
    • Blades (components) that are auto-registered and loaded at runtime.
    • Introduced the Core Blades to setup the basic runtime of an MVC application:
      • MvcBlade — wiring for MVC related components (Controllers, View Engines, etc).
      • WebBlade — wiring for System.Web components (IHttpModule, etc.).
      • RoutingBlade — wiring for the IRouteConfigurator implementation.
    • RotorContext that works with the Blades to setup the runtime.
  • Auto-registration of View Engines (VE)
  • Auto-registratrion of MVC Filters to support constructor injection.
    • Added new InjectableFilter attribute to associate a filter to an action.
    • Added support for IActionFilter, IAuthorizationFilter, IErrorFilter and IResultFilter
  • InferredViewResult handles inferred actions and reports HTTP 404 for missing actions.
  • Works with ASP.NET MVC in Mono

 

Service Orientation Requires Data Orientation

More and more the conversations are around SOA.  This one article at InfoQ stuck out to me regarding ‘service data’

Most of today’s SOA literature and implementations concentrate on defining business aligned services and rarely discuss the role and impact enterprise data has in the context of SOA

 

How to Uninstall – or make Message Stop loading up on Windows 7?

How to uninstall/remove Messenger on Windows 7 ?    My dad just got a new computer with Windows 7.  Anytime he starts it up, it wants him to sign in to Messenger.  He doesn’t use Messenger, and doesn’t want to use Messenger. 

What I find irritating is there isn’t any ‘don’t show this on startup’ or ‘turn this off’ within the Messenger pop-up.  At best you have to go out to the internet and start looking for hacks or ways to turn this off.

Microsoft – I don’t mind if you want to promote your own chat program in your OS, but please be kind enough to make it easy to turn off for non-computer expert users. 

Caliburn SL Nav Walkthrough/Intro

I’ve blogged in the past regarding ‘Caliburn’ by Rob Eisenberg.  Just a reminder:

Designed to aid in the development of WPF and Silverlight applications, Caliburn implements a variety of UI patterns for solving real-world problems. Patterns that are enabled by the framework include MVC, MVP, Presentation Model (MVVM), Commands and Application Controller.

Rob is in the process of ‘releasing various starter kits/samples for Caliburn’.  His first sample just recently released is :

Silverlight Navigation Walkthrough

Using jQuery to Scroll Just in Time for Paging Records..like Bing

Rob Conery blogs about using jQuery to scroll down a list of records with ‘just in time scrolling’ for paging.  Pretty cool – I have seen this feature used in different application.  I suspect this will become the defacto standard in paging lists.  Check out his how to here.

TFS Offline

Quote of the day… ‘Don’t work offline’.  I’ll keep the source of that quote unnamed, but I did think it was rather funny.  I hope TFS improves it’s offline capabilities.  This is very reminiscent of Visual SourceSafe – which I really didn’t like much.  SVN, Git, etc… all have pretty good offline capabilities.   While we are at it – I do hope TFS also integrates with explorer so if you edit a file outside of studio that it picks it up.  (Maybe you can, but I haven’t seen it).

UPDATE  I’ve been corrected that TFS does provide explorer integration with the  TFS power tools.

(My only response though… I was told this has been around since 2005… seems almost 5 years later this would be an installation option for TFS for Visual Studio ?  Guess you just have ‘know’ this is available – lol)

Google Docs

I am setting up my ‘Google’ realm of Wave, Gmail, Docs, Reader, etc… so far… I’m loving it.  Just recently I received an email with Excel spreadsheet.  Opened it up in Gmail, which prompted to use Google docs !  Worked out great.  And to share that document with my wife, I didn’t have to forward that document around.  Just share it exclusively to her.  All stored up securely on the Google cloud.

I did notice in the Excel to Google Doc conversion that lookups aren’t exactly the same, so it didn’t properly convert the lookup lists.  I hope they fix that.   I really see the world approaching of using this approach more and more.   With the cloud storage, feature rich word processor, spreadsheet and slide creation capability… who needs an expensive desktop copy of Office!

Steve’s Final ‘Thoughts of the Day’ – (or rather ‘Stirring the ORM Pot in the .NET world…’)

Douglass Starnes has a series on different data model approaches with asp.net mvc, showing how to setup them up and use them.

In part II of the series he makes this comment: 

In the ASP.NET MVC space I see three ORMs being used most commonly.  By far the favorite outside of Microsoft is NHibernate.  Inside of Microsoft there are two competing offerings: LINQ to SQL and Entity Framework.

This view/perspective – is it a correct one ?  Is Microsoft competing against NHibernate OSS .NET projects created by it’s own community ?  Or is Microsoft just giving more options ?  Microsoft doesn’t need to include NHibernate in any of it’s products – too many legal traps I’m sure.  What if it didn’t create it’s own ORM and merely demo’d features using NHibernate in it’s examples ?  I’m all for competition to make products better, but in this case, is MS having 2 ORM’s that are catching up in functionality, but still lagging behind NHibernate and other .NET ORM’s in the market a wise thing ?  Is that how you see it ?  I went to use EF in a project, but because it didn’t handle an ‘append only’ with ‘hilo’ id generation – and because it wasn’t poco based – where the entities are the domain objects – it was finally deemed impossible to use.  Meanwhile, we prototyped NHibernate and were able to implement everything needed in the Legacy system.  Personally, I want to pick the best of breed, not pick something just because of ‘who’ makes it.  

I don’t want to distract from his series, but that comment seems to be a prevailing one in the .net community.   What I wonder is ‘doesn’t Microsoft understand that is how it will be perceived’ – and if so… is their position to outdo the products, or do they consider this a core piece of the .NET framework to provide ORM solutions ?

I keep pointing to jQuery and ASP.NET MVC – they provide jQuery in the project templates for ASP.NET MVC.   How does that compare to including NHibernate support – or even just promoting it without including it ? 

Personally I can think of 3 examples of where they could make a difference:

1. Provide a Linq provider just like they did for EF and L2S (yes, there are Nhibernate linq providers in work – there is a basic one available now)

2. Provide a NHibernate DomainService out of the box for RIA.NET

3. Provide support for NHibernate out of the box for ADO.NET Data Services.

All three could be extensions that are referenced but included in each release.

Craftsmanship Dilemma:

Last thought… I was told to just ‘get something done’ basically… hack it.  No tests, no real design, just get it done now.  Do you think that is ok ?  How does that compare to craftsmanship ?  I don’t think I have to craft the perfect 100% solution, but how it gets built – ie. with a test, with some design/OO principles in place – shouldn’t we push back a bit to not just create ‘junk’ ?  I am noticing this trend in many industries.  Just ‘build the car’, doesn’t have to last, we need it cheap and now to compete.  At what point does quality matter ?  How would you feel if the rollercoaster your going to ride is built with that mentality?  Or the bridge ?  Or the airplane ?  Or how about the breaks on your car?  Why isn’t software engineers able to defend their craft in these situations ?  I guess it’s all about the $$$  ?  There is ‘agile’ … then there is ‘craftsmanship’…

 

Well, that is enough for the day – everyone have a great weekend!

Re-Linq Update

September 17th, 2009

Re-Linq… the ‘better Linq’   :)

The re-motion team has updated their blog with some information on re-linq:

http://www.re-motion.org/blogs/team/archive/2009/09/04/59.aspx#feedback

Additionally, Steve Strong, who is working on the NHibernate re-linq provider, he has an updated progress report (9/15/09):

http://blogs.imeta.co.uk/sstrong/archive/2009/09/15/756.aspx

Good stuff  — who knows, might make for a good Christmas present  :)

Clarification of NHibernate ‘Update’ – used to ‘Attach’

August 5th, 2009

Some of the wording on the NHibernate Session functions can be a tad misleading, or hard to understand.  One is ‘Update’, Update in many ways should be called ‘Attach’!  So, let’s review what Update does:

Session.Update

This sounds like something you call to ‘save’ something right?  Actually it’s not.  The ‘save’ occurs on Save/Commit/Flush.  ie.

using var tran = new Transaction
  Order order = Session.GetById(…)
  order.Updated = true;
  Session.Update(order)     <— not needed
tran.Commit()

Update is actually for ‘tracking’ – not saving.  Let’s say you have an object that is detached from a session – by calling Update on that object will tell NHibernate to start tracking the object again.

ie let’s say we get Order from the HttpSession…

Order order = Session[“Order”] as Order;
Session.Update(order)
tran.Commit()

So, in summary ‘Update’ is for re-associating an object back to the the NHibernate session.   Here is the catch as well – it is telling NHibernate that it is expecting it to be ‘saved’.  You can use Lock and define a LockMode to tell NHibernate that a ‘save’ might not be required.

In a test simulating a n-tier environment, I did detach (Evict) the object, then call ‘Update’ and ‘Lock’, it was able to save the object.  I plan on seeing how to work with optimistic concurrency.

What I find interesting is how badly Linq to Sql appears to handle this vs. NHibernate.  This is what I’m researching at the moment, so if anyone has advice in this area let me know.

NHibernate 2.1and NHibernate Linq 1.0 Released

July 20th, 2009

NHibernate 2.1 has been released

Read more here

Ayende also announces the RTM of NHibernate Linq 1.0  – this is fantastic news!

A couple of items with NH Linq to keep in mind:

This Linq release support just about anything that you can do with the criteria API. We do not support group joins or subqueries in select clauses, since they aren’t supported by the criteria API. NHibernate’s Linq support has been tested (in production!) for the last couple of years, and most people find it more than sufficient for their needs.

https://sourceforge.net/projects/nhibernate/files/NHibernate/2.1.0.GA/NHibernate.Linq-1.0.0.GA-bin.zip/download

As FYI, NHibernate.Linq includes the NHibernateContext class that supports the IUpdateable and IExpandProvider interfaces required by ADO.NET Data Services (thanks Shawn)

More on NCommon

June 4th, 2009

Once again, I’m going to talk about NCommon.  I want to share some of Ritesh Rao’s posts on concepts that NCommon incorporates.  I’m very impressed with his architecture and it helps that he provides NCommon for NHibernate, Linq2Sql, Entity Framework (and I see he is venturing into EF v2).

My last post touched on this, but I’ll review it again:

  1. Framework for implementing a Unit of Work Pattern
  2. Framework for implementing a Repository pattern that utilizes Linq
  3. Framework for implementing a Validations and Business Rules
  4. Implementation of the Specification pattern using Expressions
  5. Utility class to help store application specific data in the Thread Local Storage / Current Web Request and AppDomain Level Storage
  6. Guard class that mimics common guard statements that verify parameter values and throws exceptions if values are not acceptable.

NCommon uses the Apache License 2.0

NCommon uses the  Microsoft.Practices.ServiceLocation – this allows you to plug in your dependency inversion container of choice.  

I have gotten rid of the generic IoC wrapper implementation from the library as it doesn’t seem necessary anymore with the rally behind the Common Service Locator project.

This is shown in the accompany tests setup:

[SetUp]
        public void SetUp()
        {
            EFUnitOfWorkFactory.SetObjectContextProvider(() =>
            {
                var context = new TestModel();
                return context;
            });
            var locator = MockRepository.GenerateStub<IServiceLocator>();
            locator.Stub(x => x.GetInstance<IUnitOfWorkFactory>())
                   .Return(new EFUnitOfWorkFactory()).Repeat.Any();
            ServiceLocator.SetLocatorProvider(() => locator);
        }

NCommon sets the object context and implements the IUnitOfWorkFactory (the above shows with Entity Framework).

An example of how this is used can be found in the UnitOfWorkScopeTransaction class (UnitOfWorkScopeTransaction.cs- trunk/NCommon/src/Data)

ie. the ‘GetTransactionForScope’ method to retrieve the UnitOfWorkFactory:

 
var factory = ServiceLocator.Current.GetInstance<IUnitOfWorkFactory>();
var newTransaction = new UnitOfWorkScopeTransaction(factory, isolationLevel);
newTransaction.AttachScope(scope);
CurrentTransactions.Add(newTransaction);
return newTransaction;
 

The NCommon tests highlight the features of NCommon as well, including Fetching Strategies, Specification, Repositories, and Unit of Work.

Let’s look at some of Ritesh’s posts…

http://www.codeinsanity.com/2009/04/repository-pattern-thoughts.html

Some key items in this post to quote:

repositories should really represent a queryable data store that doesn’t abstract away queries behind methods that some unfortunate developer has to maintain and evolve, but rather allow consumers of the repository to query it directly. Hence why NCommon relies on repositories to implement the IQueryable interface to provide a query infrastructure directly on top of NCommon repositories.

I think this is an important piece to understand, and Ritesh follows up with the comment:

The approach I would take is rather than exposing the infrastructure requirements in the query object, I’d like it to take in an IQueryable and return back a IQueryable. This will allow chaining of queries by multiple of such Query objects without exposing any infrastructure concerns.

…

The problem with exposing ICriteria, or any other infrastructure component, to all layers of the application is that eventually a lot of infrastructure concern creeps into layers of the application where they don’t belong. I dislike the idea of having the expose ICriteria to the UI for adding paging and sorting on top of the query encapsulated by ICriteria.

That being said, in my opinion IQueryable is best suited for this job. Its a framework level member that is infrastructure agnostic, provides a very nice way to chain queries together and encapsulates our query requirements rather well.

» Read more: More on NCommon

NHibernate Validator

May 1st, 2009

Ayende has posted about the NHibernate Validator

I’ve been using a custom validator library (that uses attributes like this one).  However, seeing what the NHibernate validator provides, I’d stick with it – since the validation is called on save on the dev behalf.

Ayende also shows how to pull out the errors.

As per his post, you can read the documentation on the library for further information.

As always, good stuff from Ayende!

Windor WCF Integration…bump!

February 21st, 2009

Mike Hadlow’s blog has a great writeup on using Castle Windsor with WCF.

http://mikehadlow.blogspot.com/2008/11/windsor-wcf-integration.html

Also included is information on using WCF with Windsor/NHibernate:

http://mikehadlow.blogspot.com/2009/02/wcf-windsor-integration-using.html

I followed his advice, pulled down his sample code, and was quickly able to implement in my WCF services.  Thanks Mike!

NHibernate MultiCriteria

September 22nd, 2008

Today I ran across an interesting problem – I needed to query to get counts after a process runs.  Obviously I can make two database calls, but I instead wanted to take advantage of NHibernate’s ‘MultiCriteria’ capability.  This will make one call to the database with the 2 queries vs. 2 database calls.  My example:

 

IMultiCriteria crit = NHibernateSession.Current.CreateMultiCriteria()
                .Add(CreateCriteria<CompanyDeposit>()
                    .Add(Restrictions.Between("ProcessedDate", lo, hi))
                    .SetProjection(Projections.RowCount()))
                .Add(CreateCriteria<EmployeeDeposit>()
                    .Add(Restrictions.Between("ProcessedDate", lo, hi))
                    .SetProjection(Projections.RowCount()));
            IList results = crit.List();
            var companies = (IList)results[0];
            var employees = (IList) results[1];

            var companyCount = (int)companies[0];
            var employeeCount = (int) employees[0];

 

 

One queries CompanyDeposits and gets the rowcount, the other queries EmployeeDeposits and gets it’s rowcount.

Slick…

For reference, check out Ayende’s post here as well 

(and thanks to Stefan for asking me about it, which made me want to go try it out… lol)

NHibernate – AutoGenerated Identity on a Non-Key Field

September 10th, 2008

We have a requirement to store an additional auto-incremented id to support a legacy app upgrade.  Our primary key is a GUID – the old system used ints, and the client still wants to have that int id – as they use it, etc…

So, within NHibernate we were able to add the following to the property:

property name="GroupId" type="int" generated="always" insert="false" />
 
Thats it.