nhibernate

NHibernate Eager Loading Collections + Paging

Here is an example of my entities that I am trying to return with eager loaded collections. Mixes -> Tracks (collection) -> Tags (collection) I need to return a paged list of Mixes with eager loaded tracks & tags, without paging it is relativly simple by using the Future<>() function to run multiple queries for the tracks + tags. Be...

How to use NHibernate to process multiple resultsets/SYS_REFCURSOR from Oracle stored procedure

I can get NHibernate (v2) to return and process a single SYS_REFCURSOR that contains my single resultset. Is it possible for multiple resultsets/SYS_REFCURSOR's in NHibernate? What would be the syntax of the .hbm.xml file to map multiple resultsets from the SYS_REFCURSOR's? thanks. ...

.NET - Strategy for multi database support

Our current web application is using SQL Server, we have a requirement for support Oracle now. There are a few options: Data Facade pattern: use Data Facade interface in Business Layer, so SQL Server and Oracle can have their own implementation of Data Access Layer. The problem is it's hard to synchronize DAL code for different type o...

String[] type property mapping on nhibernate...is possible?

Is possible mapping vector types on nhibernate? I have a property like this... string[] myDesc and I would map every vector value to a specific column of my table...for example: myDesc[0] --> myDbColumn01 myDesc[1] --> myDbColumn02 myDesc[2] --> myDbColumn03 ... Is there any way to do it? ...

NHibernate - save user id of creator from username

Hi all I'm trying to use NHibernate in a project. All my domain tables include a 'CreatedBy' field which is a foreign key to the Users table. Since this is an ASP.NET app, the only information I have about the user at the time of saving is the username, from the cookie. What is the best approach for obtaining the user ID and saving it ...

How to convert an NHibernate.Expression.Order object into a string?

I have a list of NHibernate.Expression.Order objects and want to convert them into a sql string. i.e. "Name ASC, Id DESC, Amount ASC" ...

Cannot set entity properties in NHibernate event listener.

Hi all I'm overriding NHibernate's PreInsertEventListener in order to set the entity's DateCreated property to DateTime.Now. Here is my code: public bool OnPreInsert(PreInsertEvent e) { DomainObject domainObject = (DomainObject) e.Entity; if (domainObject.CreatedById == 0) throw new Exception("The " + domainObject.GetType().Name +...

NHibernate.QueryException: could not resolve property

Hello all, I'm using FluentNHibernate and Linq To Nhibernate, with these entities (only the relevant parts): public class Player : BaseEntity<Player> { private readonly IList<PlayerInTeam> allTeams = new List<PlayerInTeam>(); public IEnumerable<Team> Teams { get { return from playerInTeam in all...

NHibernate Subquery with OrderBy

Hi, I have 2 entities... Audio Tag These are setup as a many-to-many, Audio has a reference to Tags, but Tags doesn't have a reference back to Audio. What i want to do is return all tags matching a search query with a count of how many Audios for each tag, they also need to be ordered by the Tags with the most Audio items. Just to m...

NHibernate session management in NServiceBus with Autofac

Andreas Ohlund has an excellent article here on how to use Structuremap to wire the NHibernate session so that it enlists in the NSB transaction automatically. Does anyone know if it is possible to achieve the same with Autofac? ...

How to do deep copy of NHibernate Objects ?

Hi all, I am trying to do a deep copy of a NHibernate object (proxy wrapper). I want to do a copy of lazily loaded things also, except the Id of each inner object of the parent object, as it should be generated when I save the new object which is the result of deep copy. I have tried to use serialization and also tried using AutoMapper...

scoping NHibernate ISession in a spawned Thread with NInject

Ok, here's the scenario. I have an ASP.NET site that periodically spawns a background thread to do some jobs. the thread's execution consists of a JobRunner that iterates through a list of IJobs and calls Execute() on each one. JobRunner and each IJob is created by NInject. A couple of the IJobs have a dependency to IRepository<Model...

Questions with different types of answer in NHibernate

I'm trying to find a tidy solution to a questionnaire problem. Let us say that I have a Questionnaire class which has a collection of Answers, e.g. public class Questionnaire { public virtual ISet<Answer> Answers {get;set;} } Answers need to be of different types depending on the question, e.g. date of birth, marks out of ten, why...

NHibernate: why do non-persistent properties have to be marked as virtual for lazy loading.

I kind of get that in order to allow lazy loading, NHibernate needs to generate a proxy class which extends the POCO class. And so I guess NHibernate needs to override the implementation of the persisted properties, and you have to mark them as virtual. What I don't get is why I have to go round marking almost everything else as virtual...

Nhibernate cache problem while using SQL Server triggers

Hey! I am using Nhibernate with Fluent, to persist a SQL Server 2008 express database in a business application. I have a class named Receipt which contains a list with many objects named ReceiptItems. The user can create a receipt, add Receiptitems to it, and edit it as long as its not marked Finished. This part works well and saves t...

simple joined-subclass example tries to update the identity column of the base table

Hi, I must be missing something very important in the concept to get this error so any help appreciated. I get ----> System.Data.SqlClient.SqlException : Cannot update identity column 'ProductID'. when i run this var tblEvent = session.Load<TblEvent>(17); tblEvent.Code+= " - test update"; using (var tran = sess...

AppFabric: Could not contact the cache service

I'm trying to use AppFabric with NHibernate as my second level cache provider but I'm getting the following error: ErrorCode:Initialization: Could not contact the cache service. Contact administrator and refer to product help documentation for possible reasons. I presume that the problem is with my configuration in web.config: <sec...

How to transfer data from database to and from XML

I like to use xml as interchange format between different databases. The xml format is standardized (xsd) and also the database schema is pretty fix. My tasks now is to map between those worlds. Is there a kind of "mapper" to transform xml to sql databases in a bidirectional manner? I like something similar to the mapping files used in...

ActiveRecord: how to find constraints?

I'm kind of new to ActiveRecord (using CastleProject) and gaining knowledge step by step. Now I'm running into another situation. I've got a Media class that is used in some other classes: Content, Case and Service. Now when I want to delete a Media class, I want to check if there are any constraints with the previous named classes. I...

How to efficiently update models with references(dropdownList )with asp mvc and nhibernate

Hello, I started to develop a web application (application portfolio) with nhibernate and asp mvc2. I have some difficulties to properly change the category of an application. Here are my models: public class Application { public virtual int Application_ID{ get; private set; } public virtual string Name { get; set; } pu...