Community Blogs

Browse by Tags

Related Posts

  • An xVal Provider For NHibernate Validator

    I wrote a post about a month ago about using xVal with NHibernate Validator 1.2 which solved a problem I was having upgrading the xVal ‘in-the-box’ provider to work with a newer version of NHibernate Validator . There was a caveat that my solution only worked for ValidatorMode.UseAttribute and I wouldn’t catch XML or Loquacious (or other?) validation.  This seemed to work OK, but Fabio Maulo wrote a comment to that post saying NHV has metadata which should be the same no matter which validation mode was used. So I decided to investigate how I could get the metadata without resorting to the NHibernate.Validator.Mappings validationMode specific engines (I was using ReflectionClassMapping, but there are others like XmlClassMapping). I think...


  • NHibernate 2.1.1 Released

    Get it here . Intersting to note, the API documentation is now available in CHM format. Read More...


  • Which ORM? LINQ To SQL, Entity Framework? LLBLGen? NHibernate?…?

    While I was planning to write about the same topic and have the draft ready in my Windows Live Writer waiting to complete, I found an interesting question in StackOVerflow and couldn’t just resist to answer: ORM/Persistence layer Advice The question starts with: I'm starting a new project and I'm looking around for either a very good ORM or for a non-SQL-based persistence layer. Then follows up with a REALLY GOOD summary of what he believes about each known ORM he knew out of his own findings and search. I advice you to go read it. However, all this investigation didn’t get him to a single choice answer. And I can’t blame him. This is one fo the questions that will remain for so long without a single answer, or maybe having the popular...


  • Fluent NHibernate with System.ComponentModel.DataAnnotations

    So I’m building a product with NHibernate and possibly another ORM. The main focus of the app is a ASP.NET MVC 2.0 web application . So I, obviously, want the built in validation client-side in JavaScript and server side. By default, the MVC stuff uses the System.ComponentModel.DataAnnotations attributes to validate properties on your domain. What I REALLY wanted was to use the Data Annotations with Fluent NHibernate for my DB mapping files. This presents a problem, right? WRONG! Because Fluent NHibernate is so extensible, I can easily create a convention to use the Attributes. Then all I have to do is add the convention to my Fluent NHibernate AutoMapper instance and the properties with the attributes are just taken care of. Isn’t that neat...


  • Major Hack: Repository Tests With NHibernate And SQLite on a CI Server

    I recently setup my first continuous integration build server using JetBrains’ TeamCity product, and it couldn’t have been much simpler. However I kept running into an issue with my test projects whenever I was using NHibernate or SQLite (very useful or regression tests against an in-memory database). The Problem Everything would run correctly locally using MSTest, but when TeamCity ran the tests I would get the following error: Unable to load type 'NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle' during configuration of proxy factory class. Possible causes are: - The NHibernate.Bytecode provider assembly was not deployed. - The typeName used to initialize the 'proxyfactory.factory_class' property of...


  • Required Validator For NHibernate Validators

    I’ve recently switched from the Enterprise Library Validation Application Block to using NHibernate Validators. If you are not familiar with the NHibernate Validator project, they are part of the NHibernate Contrib project and offer Validation constraints, and validation runner, and tight integration with NHibernate (especially great if you use NHibernate to generate your DB). One of the main reasons for my switch was integration with xVal (which EntLib Validation’s implementation prevents), and also to get some advanced but common validators like Email, Size, NotNullNotEmpty. Anyway, I would recommend that you look at NHibernate Validator if you use NHibernate and are looking for a validation framework.  However, this post is about writing...


  • ADO.NET Data Services and NHibernate

    With the arrival of the LINQ provider for NHibernate, NHibernate now supports ADO.NET Data Services. There are some restrictions, however: Relations must be entities or simple collections of entities (Entity, IList, IList<T>), not sets (ISet<T>, HashSet<T>) or maps (IDictionary, IDictionary<K, V>, HashTable); The ID property must be called either "ID", or end with "ID", for example, CustomerID; The ID property must have a public setter as well as a public getter; The ID property must be of a base type, such as int or string; The collections to expose must be properties of type IQueryable<T> or IOrderedQueryable<T>. Here is an example: public class Customer { public virtual Int32 ID { get;...


  • Manually Indexing an Entity with NHibernate Search

    NHibernate Search, which you can get in source format with SVN from the NHContrib trunk here , is an API that integrates NHibernate with the popular indexer Lucene.NET. Out of the box, it indexes the properties from your entities, the way you want it to (at the moment, only by using attributes), at insert/update/delete time, through the use of listeners. But what if you want to index an entity that already comes from the DB? Let's see how this can be done. First, out entity: [Indexed] public class SomeClass { [DocumentId] public virtual Int32 Id { get; private set; } [Field(Index.Tokenized, Store = Store.Yes)] public virtual String SomeProperty { get; set; } } Then, use this code: Configuration cfg = ...; ISession session = ...; SomeClass...


  • Finding Dirty Properties in NHibernate

    Sometimes there may be a need for finding out if a specific entity, or a property of that entity, was changed, or, better yet, the original value for that property. Below is a set of extensions for ISession that give you just that. public static class SessionExtensions { public static Boolean IsDirtyEntity(this ISession session, Object entity) { String className = NHibernateProxyHelper.GuessClass(entity).FullName; ISessionImplementor sessionImpl = session.GetSessionImplementation(); IPersistenceContext persistenceContext = sessionImpl.PersistenceContext; IEntityPersister persister = sessionImpl.Factory.GetEntityPersister(className); EntityEntry oldEntry = sessionImpl.PersistenceContext.GetEntry(entity); if ((oldEntry == null) && (entity...


  • MVCContrib FluentHTML Select Lists and NHibernate

    When using ASP.NET MVC you will eventually want to do a select (drop down) or even a multiple select list, and your first though might be to use <%= Html.DropDownList %>.  Unfortunately you will soon notice that ASP.NET MVC always looks for a match between the name of the dropdown and a property on the model, and if it finds a match, it OVERRIDES the selected value(s) of the select list.  Now of course not being able to reliably set the selected value(s) is a major problem – if you Google this you will get a ton of results and most people solve the issue by just changing the name of the Html.DropDownList(“name”) to something that doesn’t match a model property. Of course we can put this into the “hack” or “workaround” category...


Page 1 of 12 (113 items) 1 2 3 4 5 Next > ... Last »
Microsoft Communities