I’ve never known anyone at one of these sessions to say anything controversial. About for instance LINQ-2-SQL. Repeatedly.
Someone’s trying to start an argument... I’m of the view (stolen from someone I forget) that not using an ORM in a business app is stealing from your customer.
L2S is fine for small things but has definite scalability and other limitations. NHibernate scales up much better, but isn’t as easy to start with. There’s an inflection point where a project would be better using NHibernate, where exactly this is varies.
The initial learning curve for L2S is lower, but you can’t go as far. L2S does do some nifty things. I’ve been impressed with some of the queries it produces which are remarkably efficient. And the ability to switch to LINQ-to-Objects can be useful if you want to load the data into memory and run the queries there without rewriting everything. You do need to watch it closely so it doesn’t revert to that behaviour unintentionally though. It’s a useful tool at the low end. I’ll never use it by choice, but for small things I won’t condemn it.
AutoMapper rocks muchly, but I’ve used it on L2S projects so I can’t say it’s a point in favour of NHibernate. Things like a mapping strategy that scales to many objects and per query fetch plans are much better arguments.
I’ve got a project going at the moment where we are using FNH/L2NH and we have a mix of both automapped classes, some of which have overrides, as well as HBM files (for messy things like ternary associations that FNH doesn’t handle too well).
It works great. Here’s what the code looks like when we kick the session object into existence.
var model = AutoMap.AssemblyOf<SomeEntity>()
.Where(t => t.Namespace == "AAA.Entities" && !typeof(IUseHbmRatherThanAutoMap).IsAssignableFrom(t))
.UseOverridesFromAssemblyOf<SomeEntity>();
var sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005
.ConnectionString(c => c.FromConnectionStringWithKey("ConnectionString"))
.Cache(c => c
.UseQueryCache()
.ProviderClass<HashtableCacheProvider>())
.ShowSql())
.Mappings(m =>
{
m.AutoMappings.Add(model);
m.HbmMappings.AddFromAssemblyOf<SomeEntity>();
})
.BuildSessionFactory();
Too easy!
And before you ask, yes, we could’ve decorated our classes with an attribute rather than use an interface for excluding the HBM’ed entities from automapping. The advantage to the interface approach is that it’s really easy to find all the classes that have HBM mappings via R# (find interface implementers) plus it makes the code little cleaner to look at since we don’t have to do any reflection to process attributes.
Regards,
Richard
Banks
CSM | CSP | http://richardsbraindump.blogspot.com
| http://twitter.com/rbanks54
Was a really good meeting last night and we covered quite a bit of content in a short (except for Adrian ;-)) space of time. Really got a lot of value from Rhys' Mass Transit presentation.
Thanks to everyone who presented :)
Kind Regards,
Jarred
Sargent
Readify | Senior Developer
Suite 408 Life.Lab Building | 198 Harbour Esplanade | Docklands | VIC 3008 | Australia
M: +61 414 483 208 | E: jarred....@readify.net | C: jarred....@readify.net | W: www.readify.net
![]()
The content of this e-mail, including any attachments is a confidential communication between Readify Pty Ltd and the intended addressee and is for the sole use of that intended addressee. If you are not the intended addressee, any use, interference with, disclosure or copying of this material is unauthorized and prohibited. If you have received this e-mail in error please contact the sender immediately and then delete the message and any attachment(s).