nhibernate

NHibernate - Lazy Loaded Collection

Should a lazy loaded collection in NHibernate ever give me a NullReferenceException? I'm getting an exception in a method like the following: public void Test(ISession session, int id) { var entity = session.Load<MyEntity>(id); entity.LazyLoadedCollection.Add(SomeItem); } The call to LazyLoadedCollection is throwing. My mappi...

Is it possible to bind a scalar query result to a property in nhibernate?

I have an entity which has a property that does not get its value from the entity's table. But it could be calculated by a query if it is possible. To clarify, I have an entity of an Entry and I want to check if the current user voted it or not. So for that reason I thought that I could add a property like "IsCurrentUserVoted" to the E...

NHibernate - Sorting Entities based on Property/Column + how to manage?

I'm writting an ASP.NET MVC e-commerce app using NHibernate and I want the end-user to be able to control the ordering of Product Categories (not just have them appear alphebetically etc.). Normally, I'd add an OrderIndex/Sort column (of type int) to the Category table, and property to the Category domain class. But the problem is in ha...

How to specify a mixed table-per-subclass -> table-per-hierarchy in NHibernate HBM?

I'm mixing table mapping strategies to store a class hierarchy via NHibernate 2.1.2. I'm not using Fluent NHibernate. I understand how to map a table-per-hierarchy -> table-per-subclass structure, but not the other way around, as the XML is invalid after adding the discriminator. Here's the HBM extract: <class name="Base1" table="Ba...

What is the best NHibernate cache L2 provider?

I've seen there is a plenty of them. NCache, Velocity and so forth but I haven't found a table comparing them. What's the best considering the following criterias: Easy to understand. Is being maintained lately. Is free or has a good enough free version. Works. ...

Nhibernate listeners does not work correctly

I am using NHibernate (v 2.1.0.4000) and try to use an event Listener for an update action. I used the following code to add a listener to the Nhibernate Configuration. var configuration = new Configuration(); configuration.SetListener(ListenerType.Update, new UpdateListener()); _sessionFactory = configuration.BuildSessionFactory...

NHibernate criteria query help

Hello Given the following tables, I am trying to return all Allocations for a given Resource's that fall between a given range of dates using a criteria query: create table Resources ( ResourceId integer, ResourceName TEXT not null, BusinessId TEXT not null, OrganizationName TEXT not null, primary key (ResourceId) ) c...

Inner join between same tables in Nhibernate query API

Hi I have two Domain Objects mapped right : Emails and ActionPlans the table structure is something like: create table emails(id int identity(1,1), subject nvarchar(512), parentEmailId int, rootEmailId int) create table actionPlans(id int identity(1,1), dueDate datetime, emailId int) insert into emails(subject, parentEmailId, rootE...

NHibernate: lazy loaded properties ?

NHibernate question: Say I have a SQL table Person and it has a Picture column ( OLE Object ) . I have a class Person and it has : byte[] Picture attribute. Is it possible to map like this ? <property name = "Picture" column = "Picture" type = "System.Byte[]" lazy="true" /> Does the "lazy" keyword have any effect on properties ...

Is there a way to use Expression.In() in a case insensitive way?

I am using Expression.In() as a part of a criteria using NHibernate and for the life of me I can't find any way to make it ignore case. Does anyone know how this can be done or am I going to have to do this a different way? Not that it probably matters much but here is a sample of how I am using the Expression.In() ICriteria criteria ...

NHibernate IPreUpdateEventListener

I am trying to save entity data into separate table (serialized as a collection of key-value pairs). Seams that I cannot use BeginTransaction and Commit because I am getting NHibernate ERROR "Possible nonthreadsafe access to session" I am not an expert of of NHib but suppose the problem is that there is already some transaction started ...

Fluent NHibernate : How can i use Int64 as ID?

Hi guys, I'm quite new to the whole concept of ORM, NHibernate and FluentNH, and i'm trying to accomplish something that seems so simple... I'm trying to retrieve an object that has a field defined as Int64 in it's class. This field would be the ID, as defined in the Map file. When trying to retrieve a record from the DB, NHibernate r...

Closing SQL connections (NHibernate)

I have a test console app that is executing sql scripts to create a database and its tables, then inserting data. I use DAO to create, retrieve, update, and delete from the tables and then try and drop the database, but it can't because it says it is currently in use. How do I kill the connection? Through debugging and running a sql scri...

Understanding ICriteria for NHibernate

Please can someone explain in english what the following code does? var subCriteria = DetachedCriteria.For<UserLocation>(); subCriteria.SetProjection(Projections.Property("LocationId")) .Add(Restrictions.Eq("UserId", userId)); return UoW.Session.CreateCriteria(typeof(Location)) .Add(Subqueries.PropertyIn("LocationId"...

NHibernate: Do you always have to commit, and what does it actually do on read?

I'm using NHibernate to communicate with the database in my C# .NET project. When communicating with the database - do I always have to commit the transaction? What does this actually do when doing reads? I find myself forgetting to commit occasionally when doing reads, but everything seems to work fine. using (var tx = Session.BeginTr...

Return entity via projection query

Is it possible to return an entity using a projection query? I've successfully done it with a SQL query (see below), but can't find how to do it with a projection query. Dim sql As String = "SELECT {a.*}, {b.*} FROM a LEFT OUTER JOIN b ON a.pk = b.fk") ' Convert SQL results into entities {a} and {b} Dim query As IQuery = session.Creat...

Alternatives for NHibernate mappings?

Are there any good alternative to NHibernate's xml mappings? I have seen Fluent. All I look for is high maintainability. UPDATE : I would like to know the performance issues related with using fluent because I guess it is going to create xml mappings from the class (which can be time consuming - my guess) Thanks ...

Association references unmapped class exception

I'm trying to map the Northwind Employee entity with NHibernate: public class Employee { public virtual int ObjectID { get; set; } public virtual string LastName { get; set; } public virtual string FirstName { get; set; } public virtual string Title { get; set; } public virtual string TitleOfCourtesy { get; set; } ...

NHibernate Join and Restriction Criteria

Hi, Im trying to write an NHibernate criteria that effectively joins and restricts at the same time. My DB looks like this... Cases ---> CustomerProducts <--- Customers Cases ---> CaseStatuses Each case is associated with a customer product (Many cases to one product). Each customer has a number of customer products (One customer has...

NHibernate and XML Serialization with IList<T>

I've recently started using NHibernate, and on the whole like it a lot. Until I ran into a problem with needing to serialize to XML and back. I have a class that has a many to many relationship, so have an IList in the parent class to hold the list of child objects. Class parentClass{ IList<childClass> childList; string varA; s...