nhibernate

Efficently returning parent and child records with NHiberate

I am trying to efficiently work with parent & child (post & tags) entities. A sample of the code can be seen here: http://gist.github.com/297464 Using the following results in less than 10 distinct Post entities if any of Post contains more than 1 tag. var posts = session .CreateCriteria<Post>() .SetMaxResults(10) .SetFet...

NHibernate - Retrieve default data for non-configured fields

I have the following requirement: User Table UserID int (PK) UserName string Configuration Table ConfigID int (PK) ConfigName string DefaultConfigValue string UserConfig UserID int (PK) ConfigID int (PK) ConfigValue string How can I define my NHibernate mapping to load all of the configuration with the user value if con...

Copying template data from a table in nhibernate

I have a bunch of data that is stored in a few tables and serves as a template when a new customer or such is created. I know i could do a select and copy all the properties and execute a save, however some of the fields are large retrieving to and from the db doesn't seem the most optimal idea. I have also thought about writing a cus...

NHibernate internal data-retrieval method

Internally, does NHibernate use DataSets or SqlDataReaders to access data from sql server or does it depend? ...

Executing multiple updates in a single NHibernate HQL statement

I would like to write the following SQL in HQL so it executes as a single statement: update child_thingy c set c.parent_thingy_id = null where c.common_thingy_id = @common_thingy_id delete from parent_thingy p where p.common_thingy_id = @common_thingy_id I've translated the SQL to HQL as follows: update ChildThingy c set c.ParentThi...

Nhibernate - Create SQLQuery - IndexOutOfRangeException

Hi, we have a table named Customer which has three sub classes / tables viz. Cust1, Cust2 and Cust3 which are linked by hbm using joined-sub-class. all the 4 tables have CustomerId as the primary Key. A record in customer table will have one record either in Cust1 or Cust 2 or Cust3 table. fetching the list using the standard Nhibernat...

Stack Overflow whilst cascade saving nhibernate entity with custom generator

I'm pretty new to Nhibernate, so apologies for a long - winded description I suspect that changing the structure of the legacy DB is probably the best option, but I want to try and get NHibernate to deal with it. Basically the structure is this an EndPoint has an address and a contact. Endpoint is stored in a table with a composite ID ...

NHibernate + ASP.NET + Open Session in View + L2Cache

I am using CodeProject's well known Open Session in View to handle NHibernate Sessions. Does it works well with Level 2 Cache? Anyone has succeeded doing it? Should I use NH.Burrow instead? Any advice on l2 cache in asp.net best practices is appreciated. Edit: link to CodeProject's article: http://www.codeproject.com/KB/architecture/NHi...

Session Management in Castle Active Record

How do I manage session if I am using Castle Active Record over nHibernate. Basically I can manage the life cycle of ISession on my own if I am using nHibernate directly. But when I am using Castle AR it does not give me a way to manage the life cycle of the session. I want to use single Session per thread. I am using Castle AR in a W...

Subclasses and abstract classes in DDD

I have an abstract base class called Person with subclasses Employee and Customer. How do you deal with the situation where Employee is also a Customer? How would this series of entities be created? Cheers ...

GetCurrentSession Session Scoping for a Desktop app

Hello I very recently discovered nhibernate session scoping and contexts. It seems that using this for a desktop app is as simple as bootstrapping the configuration with a ThreadStaticSessionContext, binding the session factory to the context, and then just calling sessioonFactory.GetCurrentSession() as needed. I am looking for experie...

Retrieve NHibernate.Collections.Generic.PersistentGenericBag as IList<T> using Reflection

I'm attempting to compare a transient object graph to an NHibernate-persisted object graph. Unfortunately my code breaks where properties of type IList<T> are concerned. The code below works fine with instances of List<T>, because List<T> implements both IList<T> AND IList. Unfortunately, NHibernate's PersistentGenericBag only implements...

CreateCriteria inside Expression.Disjunction() fluent nhibernate

criteriaCount.CreateCriteria(AdvertisementsProperties.City.ToString()) .Add(Expression.Like(CitiesProperties.Name.ToString(), query, MatchMode.Anywhere)) .Add(Expression.Like(CitiesProperties.SlovenianName.ToString(), query, MatchMode.Anywhere)) .CreateCriteria(AdvertisementsProperties.Coun...

fluent mapping question-give a certain value to a property

Consider following 2 classes: public class TypeAGood{ public virtual int Id{get;set;} public virtual string Description{get;set;} public virtual Type Type{get;set;} } public virtual class Type{ public virtual int Id{get;set;} public virtual string Name{get;set;} } mappings: public class TypeMap : ClassMap<Type> { ...

Using Doctype in Nhibernate

Hi I am trying to keep common properties of base class in one location and use XML ENTITY to refer in Nhibernate mapping file. Mapping file <?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE hibernate-mapping [ <!ENTITY BasePropertyList SYSTEM "BasePropertyList.xml"> ]> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="M...

IValidator could not be located with the ServiceLocator

I get the following error when using sharparchitecture and try to call IValidatable.IsValid on a Domain Object. How can I register an instance of the NHibernate validator against the common service locator? I have seen the following unit tests: http://code.google.com/p/sharp-architecture/source/browse/trunk/src/SharpArch/SharpArch.Tes...

WCF Server Exception Handling in UI

I would like to be able to catch exception from the server and display an error beside a field that related to the error. I have a NTier client server application that uses WCF services and DTOs to pass data from the server to the client and back. I would be validating a domain object on the server and if it had error I would want to t...

Fluent NHibernate: Model Markov chain

I want to use Fluent NHibernate to model a Markov chain. It's basically a set of different states with transition probabilities between the states. I want to map the transition probabilities into MarkovState.TransitionProbabilities as a Dictionary. I want to use the NEXT state as key (using either MarkovState or int as key), so that I c...

Nhibernate multiple component properties of the same type in a class

I have a class LINE which contains two properties of type POINT. I would like POINT to be a component property. If LINE were to contain only 1 POINT, this would be no problem, but since it contains 2 POINTs I would think I needed to distinguish them (so a prefix or suffix can be applied to column names). I tried using the PropertyName a...

What is so great about ORM?

Hi, So I'm having a head against the wall moment and hoping somebody can come help either remove the wall or stop my head from moving!! Over the last 3/4 weeks I've been investigating ORM's in readyness for a new project. The ORM must map to an existing, large and ageing SQL database. So I tried Subsonic. I really liked v2 and v3 aft...