nhibernate

NHibernate FlushMode - Why Can't NH Evict Everything Not Saved?

Hi all. I've spent some time searching around how to configure NHibernate's FlushMode so it could only save objects that I've explicity called Save/Update/Delete, but I've figured out that I can't do that. Instead of it, I have to evict every object that I've modified (even without calling Save/Update/Delete) as I'm using NHibernate tra...

Retrieving distinct values in mapping

I have an existing view which has too much data in it. Unfortunately I cannot get rid of it so I need to try to work around it using my NHibernate mapping. The idea is to have NH issue the following query: SELECT DISTINCT User_Id, Module_Id, Application_Id, RightsMask FROM V_UserApplicationPermissions WHERE User_Id = ? My current ma...

NHibernate Multiple Criteria Difficulties

Hi! I'm having difficulties with multiple joins in the NHibernate Criteria search. Say I had a pet table, and I wanted to return all pets where the pet category was Dog, and the owner gender was female, ordered by the pet birthday. I've tried a bunch of permutations for how I can get this but haven't been able to figure it out. My la...

fluent nhibernate one to many mapping

I am trying to figure out what I thought was just a simple one to many mapping using fluent Nhibernate. I hoping someone can point me to the right directory to achieve this one to many relations I have an articles table and a categories table Many Articles can only belong to one Category Now my Categores table has 4 Categories and Articl...

nHibernate: limit the result set of a mapped collection

How do you limit the result set of a mapped collection in nHibernate? For instance: Model.Items; will always return all the Items for the given Model. Is there any way to force it to return only, say, 20 Items without creating a specific query ? Something like Model.Items.SetMaxResults(20); In other words, I would like nHibernate...

Stop lazy loading or skip loading a property in NHibernate? Proxy cannot be serialized through WCF

Consider I have a parent, child relationship class and mapping. I am using NHibernate to read the object from the database, and intended to use WCF to send the object across the wire. Goal For reading the parent object, I want to selectively, at different execution path, decide when I would want to load the child object. Because I don...

What is the basic pattern for using (N)Hibernate?

I'm creating a simple Windows Forms application with NHibernate and I'm a bit confused about how I'm supposed to use it. To quote the manual: ISession (NHibernate.ISession) A single-threaded, short-lived object representing a conversation between the application and the persistent store. Wraps an ADO.NET connection. Factory for ...

Computed properties in NHibernate

I'm having a problem in mapping an existing data class member to the database.. I have a database table where one of the columns is a string type, but actually stores a comma separated list of numbers. My data class shows this field as a list of integers. The problem is that I couldn't find any hook in NHibernate that allows me to invo...

How to Command Query Responsibility Segregation (CQRS) with ASP.NET MVC?

I have been reading about Command Query Responsibility Segregation (CQRS). I sort of wonder how would this work with ASP.NET MVC? I get the idea of CQRS conceptually it sounds nice and sure does introduce some complexities (event and messaging pattern) compared to the "normal/common" approach . Also the idea of CQRS sort of against the u...

NHibernate Override<> for many-to-any

I have a question for a specific many-to-any mapping problem: I'd like to have a fluent mapping for this simplified domain (non relevant properties removed) public interface IModule { Container Container { get; } } //This is mapped to [dbo].Container table in the database public class Container: Entity { // ... // I need to...

(fluent) nhibernate conditional table mapping strategy

I have no control over database schema and have the following (simplified) table structure: CityProfile Id Name CountryProfile Id Name RegionProfile Id Name I have a .Net enum and class encapsulating the lot: public enum Scope { Region, Country, City } public class Profile { public Scope Scope { get; set; } public int...

Nhibernate HQL where IN query

Im trying to return a SimpleQuery list that queries a single table and uses IN. I can get this to work using return new List<Jobs>( ActiveRecordMediator<Jobs>.FindAll(Expression.In("ServiceId", ids)) ); However this is really really really slow. So id like to do something like this SimpleQuery<Job> query = new SimpleQuery<Jo...

Is it worth migrating to NHibernate 2.x from NHibernate 1.2?

We are using nHibernate 1.2 in a system which is not performing good. Will there be some performance improvement if we migrate to latest version of nHibernate? Overall is it a good idea to migrate to the latest version of nHibernate? EDIT: I want to use following features to improve performance. 1. Second level cache. 2. Joined Tab...

Multiple tables\objects in one nHibernate mapping

Hi Folks I am trying to create an nHibernate mapping for a class structure like so: class UserDetails{ Guid id; User user; Role role; public User UserInfo{ get;set; } public Role UserRoles{ get;set; } public Guid ID{ Get; set; } } class User{ string name; int id...

NHibernate: how to handle entity-based validation using session-per-request pattern, without controllers knowing about ISession

What is the best way to do entity-based validation (each entity class has an IsValid() method that validates its internal members) in ASP.NET MVC, with a "session-per-request" model, where the controller has zero (or limited) knowledge of the ISession? Here's the pattern I'm using: Get an entity by ID, using an IFooRepository that wrap...

Nhibernate relationship table mappings

I am using NHibernate to persist information in my media player app. Basically at the minute I have a mapping setup for the Track class and for the Playlist class: Track Playlist ====== ========= Id Id Name Name FilePath etc... This is working fine...

Error: "Cannot simultaneously fetch multiple bags" when calling Configuration.BuildSessionFactory();

We are getting this error after upgrading to NHibernate 2.1. [QueryException: Cannot simultaneously fetch multiple bags.] NHibernate.Loader.BasicLoader.PostInstantiate() +418 NHibernate.Loader.Entity.EntityLoader..ctor(IOuterJoinLoadable persister, String[] uniqueKey, IType uniqueKeyType, Int32 batchSize, LockMode lockMode, ISessi...

How to map a property with formula in NHibernate?

I have a class which I want to add a property with using formula attribute. Here is the mapping that I use in mapping file. <property name="CurrentUserVote" type="Climate.Domain.Vote, Climate.Domain" formula="(select v from Vote v where v.AchievementId=Id and (v.IP=:CurrentUserVoteFilter.CurrentUserIP))"></property> As you see, I wa...

nHibernate on IIS 7, SQLClientPermissionException

I am developing an MVC application using nHibernate; running through VS's built in web server the application runs without errors. When setup and running through IIS7 on localhost, the application throws a SQlClientPermission exception after calling System.Data.SqlClient.PermissionDemand (SqlClient calls this internally) I have enabled...

Global find object references in NHibernate

Is it possible to perform a global reversed-find on NHibernate-managed objects? Specifically, I have a persistent class called "Io". There are a huge number of fields across multiple tables which can potentially contain an object of that type. Is there a way (given a specific instance of an Io object), to retrieve a list of objects (o...