nhibernate

NHhibernate OUTER JOIN

criteriaCount.CreateAlias(AdvertisementsProperties.City.ToString(), "city") .CreateAlias(AdvertisementsProperties.Area.ToString(), "area") .Add(Restrictions.Disjunction() .Add(Expression.Like("Advertisement." + AdvertisementsProperties.Name.ToString(), text, MatchMode.Anywhere)) ...

NHibernate and cascade deletes

We have a very deep object graph, and we need a way to delete a root of object graph an it needs to be happen fast. We are talking about 1000's of rows in about 10-15 tables. We also have all collections mapped as AllDeleteOrphan. We hopped that NH would execute delete by foreign key, but it actually executes delete per item in collectio...

Sharing nHibernate and hibernate 2nd level cache

Is it possible to share the 2nd level cache between a hibernate and nhibernate solution? I have an environment where there are servers running .net and servers running java who both access the same database. there is some overlap in the data they access, so sharing a 2nd level cache would be desirable. Is it possible? If this is not ...

NHibernate asks .NET to convert a string parameter to an integer, don't know why

(Edited to avoid leading down the wrong road) Before giving details, very short version: I have a SQL statement I need to get out of NHibernate, and I have Criteria API statements that give it to me. The NHibernate is trying to do something wrong with the statement it generates, and I'm trying to figure out why. I have the following m...

NHibernate child object's ID problem.

When I retrieve a Parent-object, the Child-object's ID is not always predictable. For example, sometimes it is set with 0 (zero), sometimes the actual value and sometimes -1. Why? How can I solve this problem? For code and mapping-files plz see this older question from me. ...

Using custom C# attributes to select Fluent conventions

Suppose you have sets of Fluent conventions that apply to specific groups of mappings, but not to all of them. My thought here was, I'll create custom C# attributes that I can apply to the Fluent *Map classes - and write conventions that determine acceptance by inspecting the *Map class to see if the custom attribute was applied. That ...

Unable to find assembly Nhibernate

Title says it all. I'm developing a web app using NHibernate, and getting the error Unable to find assembly 'NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' The weird thing is that it's intermittent, and when ti happens it causes the VS 2010 embedded web server to crash. But it doesn't happen on ever...

NHibernate self referencing query

How do you write this in NHibernate? criteria .CreateAlias( "CreatorObject.LastCreated", "me" ) .Add( Restrictions.Eq( this, "me" ) ); Edit: something like this without using sql Where there are two tables TypeA and TypeB where typeB creates typeA objects and keeps a reference to the last object created. criteria .Add( Restr...

StructureMap, NHibernate and ASP.NET MVC fails to lazy load

I'm urrently working on a MVC project based on StructureMap and NHibernate. It's my first time using StructureMap, so I might be using it wrong, which causes these troubles for me. In my Application_Start I initialize StructureMap like this: ObjectFactory.Initialize(x => { x.For<ISessionFactory>() .Singl...

Why does NHibernate not realise my domain object needs updating, not inserting?

Hi all I have a web page which uses NHibernate to load a domain object. The object's state is then stored in the page controls, and when the user clicks the save button, a new object is created and its properties (included the Id) are populated from the page controls. I then call session.Save() on the object. This to me means that NHib...

NHibernate - see SQL without all the other guff

So I'm using log4net to write log output to the trace. Show sql is specified in the configuration file. I seem to have to set the log output level to DEBUG to get the SQL output, but DEBUG also produces pages and pages of other guff I have to scroll past. Can I get the SQL without the guff? Thanks David ...

NHibernate - dirty ISession not updating

Hi all When the save button is clicked, the following code is run [PersistenceSession is a property returning an ISession instance]: _storedWill = PersistenceSession.Load<StoredWill>(_storedWillId); _storedWill.WillReference = txtWillReference.Text; _storedWill.IntroducerReference = txtIntroducerReference.Text; //A stack of other prope...

NHibernate - how do you know if database operation succeeded?

Hi all If for example, I call session.Save(myObject), how do I determine if the operation succeeded or if it failed because my database server has been dropped out of a hang glider? Does NHibernate throw a particular type of exception in this circumstance? Thanks David ...

Linq to NHibernate repository implementation details

I'd like to have the following API for my MyTypeRepository: var myChosenInstance = _myRepository.FindOne(x => x.MyProperty == "MyValue"); ..and for the lambda to use used to construct a linq query within the repository, which is then used by Linq to NHibernate. Is this possible? What would my repository FindOne method look like? ...

Fluent Nhibernate - Schema Mapping Question

If in my classmap I have SchemaAction.None(); and if I also have .ExposeConfiguration(cfg => { new SchemaExport(cfg) .Create(false, false); }) Can I ensure that nhib will not touch the db schema in any fashion. In other words the only write action will be that of entitie...

nHibernate updates unchaged records

When I update (with a flush) one record in a list of records retrieved from the database nHibernate is versioning all of the records that were in the original list. Retrieving a list of records from the database: using(UnitOfWork.Start()) { queuedJobs = aJobServiceManager.GetAllJobs().Where(aJob => aJob.Status == PricingStatus.QUEUE...

using the db to prevent errors in a UI presentation

I am going though this msdn article by noted DDD expert Udi Dahan, where he makes a great observation that he said took him years to realize; "Bringing all e-mail addresses into memory would probably get you locked up by the performance police. Even having the domain model call some service, which calls the database, to see if the e-mail...

Dealing with collections with Parent -Child relationships in NHibernate

I'm having a problem with finding out which children to add, update and delete when I'm dealing with two lists one with the old chidren (from db) and the other list with the modified children (from user input). Currently I have to loop through the lists and compare to find the difference. Does anyone know of a better way of doing this...

ASP.NET MVC NHibernate Model Binding

With NHibernate I no longer expose foreign keys on my domain objects, so Product no longer has a property: public int CategoryId {get;set;} but instead has: public Category Category {get;set;} Unforunately this doesn't appear to work so well with the automatic model binding in ASP.NET MVC - if I want to simply bind a form collectio...

How does NHibernate Projections.Max work with an empty table?

I'm trying to get the maximum value of an integer field in a table. Specifically, I'm trying to automatically increment the "InvoiceNumber" field when adding a new invoice. I don't want this to be an autoincrement field in the database, however, since it's controlled by the user -- I'm just trying to take care of the default case. Rig...