nhibernate

Can a collection in NHibernate be mapped as read-only?

I have a mapping defined where a parent object has a collection of child objects. In my design, I'd like to be able to delete the child objects without having to remove them from the collection on the parent object and re-saving the parent object. However, when I try this, I get the "deleted object would be re-created on save" error. ...

How do I create different sessions for different windows in a desktop application with ActiveRecord?

I'm building a desktop application with Castle ActiveRecord and want to be able to do the equivalent of 1 nHibernate session per window form. Any ideas on how can I do this with Active Record? Specifically, I have a main window that allows you to browse the data (read-only) and then you can open separate forms to edit the data. Each...

How to map many to many association in NHibernate

I have some database tables named "Project", "Employee" and "Branch". An employee can work simultaneously on more than one project. Similarly, in a project, there are multiple employees. Also, a project is conducted at a particular branch. To maintain all these relationships, I am using a "project_employee_branch" table, which will store...

Twin Lucene index directories after Nhibernate.Search upgrade

Hello everybody i've been busy upgrading our n* stack to a more recent version. We'd been using FluentNhibernate for configuration and Nhibernate.search coupled with Lucene.Net for full-text search. Everything worked fine until i changed the various versions of the libraries to the following: FluentNHibernate.dll: 1.0.0.593 NHibernate...

NHibernate - problem with eager loading

I have a ClassA that has many ClassB elements: public abstract class ClassA: IEntity<ClassA> { public virtual IList<ClassB> ClassBList { get; protected set; } ... } Then ClassB references ClassC element: public class ClassB { public ClassC CEntity { get; private set; } public Percentage Percentage{ get; private ...

Unit test fluent nhibernate ordered list mapping

I get an exception when I try to unit test an ordered list with fluent nhibernate. The code seems to run ok but my PersistenceSpecification fails! System.ApplicationException: Expected 'CareerNote.Core.Model.Section' but got 'CareerNote.Core.Model.Section' at position 0 The full code is on github: http://github.com/fodonnel/CareerNote...

NHibernate L2 Cache - fluent nHibernate configuration

I've managed to configure the L2 cache for Get\Load in FHN, but it's not working for queries configured using the ICriteria interface - it doesn't cache the results from these queries. Does anyone know why? The configurations are as follows: ICriteria: return unitOfWork .CurrentSession .CreateCriteria(typeof(Country)...

.NET ORM solution with class auto-generation: Subsonic, Castle AR, ...?

I used to work with a custom data mapping library, and curently I'm trying to switch to a more widespread ORM solution. After some experimentation, I refined my requirements to the following: able to generate usable classes from database schema (SQL Server support is enough), support for ActiveRecord pattern, programmaticaly configura...

Mapping many-to-many without a join table in Hibernate/NHibernate

I have two tables: CalendarEntry Id Date ... Holiday Id Date ... In my CalendarEntry class, I have a property like this public ISet<Holiday> Holidays { ... } which I want to associate to the Holiday instances that occur on the same Date as the CalendarEntry. However, I can't come up with how to do this. I've tried ma...

Dividing using nhibernate results in "Could not determine member from"

This is probably something simple but I seem to be lacking some knowledge of how nhibernate works. This is my code: ICriteria query = Session.CreateCriteria(); query = query.CreateCriteria(x => x.TblProjects) .Add<TblProject>(x => x.FldCurrentFunding != 0m) .Add<TblProject>(x => x.FldCurrentFunding...

NHibernate - Usefulness

I work in a software and hardware development farm. Today one of my colleagues told me that NHibernate is only useful for small projects, and for complex or large scale projects it must be avoided. Also, it makes code harder to change. Are those statements true? ...

Where should the transaction boundary be in a repository pattern?

I have a repository like so: public interface IRepository { void Save<T>(T entity); void Create<T>(T entity); void Update<T>(T entity); void Delete<T>(T entity); IQueryable<T> GetAll<T>(); } My question is, where should my transaction boundaries be? Should I open a new transaction on every method and commit it befo...

[NHibernate and ASP.NET MVC] How can I implement a robust session-per-request pattern in my project, while focusing on information hiding?

I'm currently building an ASP.NET MVC project, with NHibernate as its persistance layer. For now, some functionnalities have been implemented, but only use local NHibernate sessions: each method that accessed the database (read or write) needs to instanciate its own NHibernate session, with the "using()" directive. The problem is that ...

NHibernate: get rows that don't have a foreign record in a different table using Criteria API

So I have Transactions and GLAllocations. I want to get all Transactions that don't have a corresponding record in the GLAllocation table. The following SQL produces the results I want. select t.* from [Transaction] t left join [GLAllocation] gla on gla.TransactionID = t.TransactionId where gla.glid is null Is there a way to represent...

NHibernate SessionFactory Configuration

When we configure the Nhibernate session factory, with fluentnhibernate, we can add the mapping files using AddFromAssembly, AddFromAssemblyOf, or Add. The first two scan the assembly for the ClassMaps. Probably there is no considerable difference, but which one is the best in terms of reducing the sessionfactory creation time? Maybe «Ad...

Getting index of a row in a list

Hi, I have a paging method that uses the criteria API's SetMaxResults and SetFirstResult. Functionally, it works fine. What I'd like to do now is provide another method that retrieves the index of a given item within the set of all items, thus allowing me to calculate what page that item is in. I am able to calculate the index correct...

How to map a database view using ActiveRecord?

Has anybody tried mapping database views in oracle using ActiveRecord? Please can I get some sample code for that? ...

NHibernate HQL SELECT TOP in sub query

Is there a way of using SetMaxResult() on a sub query? Im writing a query to return all the order items belonging to the most recent order. So I need to limit the number of records on the sub query. The equivalent sql looks something like: SELECT i.* FROM tbl_Orders o JOIN tbl_OrderItems i on i.OrderId = o.Id WHERE o.Id in (SELECT TOP ...

How to structure domain model when using NHibernate Search/Lucene

I am messing around with NHibernate Search and Lucene to create a searchable index of legal entities. My domain model looks somewhat like this: [Indexed] public abstract class LegalEntity : AggregateRoot { public virtual Address Address { get; set; } } public class Person : LegalEntity { public virtual string FirstNames { get; ...

nHibernate strategies in a web farm

Our current project at work is a new MVC web site that will use a WCF service primarily to access a 3rd party billing system via a web service as well as a small SQL database for user personalization. The WCF service uses nHibernate for the SQL database. We'd like to implement some sort of web farm for load balancing as well as failove...