nhibernate

NHibernate inteceptor not called for changes in many-to-many set/list

I have an application that uses NHibrenate and I'm using an interceptor based solution for logging/auditing. Basically I have a class inheriting from EmptyInterceptor and overriding OnFlushDirty, OnSave and OnDelete. Everything works perfectly - except - when I add or remove from a set or list that is mapped using many-to-many without ...

translate a mysql query into nhibernate

Good day! Please, can you help me to translate such a mysql query into nhibernate SELECT sales_id, service_id,dayofyear(dt), max(dt) FROM clients.statistics group by sales_id, service_id,dayofyear(dt); ...

Nhibernate - Referencing transient objects in disconnected sessions.

Hi, I've been banging my head against a brick wall for nearly two days on this so any help would be great. The scenario I've got is basically this. I have an object called Campaign which I'm creating from scratch in a web client. The Campaign has a reference to another object, Portal. The Portal has been pulled from the database thr...

nHibernate Key Column Attribute Insert=false

How do i do an insert false on key attribute like the way we do for join ...

How to manage sessions in NHibernate unit tests?

I am a little unsure as to how to manage sessions within my nunit test fixtures. In the following test fixture, I am testing a repository. My repository constructor takes in an ISession (since I will be using session per request in my web application). In my test fixture setup I configure NHibernate and build the session factory. In my...

Problem using SetFetchMode in NHibernate

i have this method: public IEnumerable<Album> GetAllAlbumsWithTracks() { var albums = Session.CreateCriteria(typeof(Album)) .SetFetchMode("Tracks", FetchMode.Eager) .SetResultTransformer(new DistinctRootEntityResultTransformer()).Future<Album>(); return albums; } but if i set .SetMa...

Is there a way to include math in the where clause of a NHibernate ICRiteria Query?

I am stumped trying to do a query like this SQL query with the NHibernate criteria interface: SELECT * FROM TimeTrack t JOIN Customer c on c.ID = t.CustomerID WHERE t.StartTime + t.EndTime < c.MaxTime I know I can do it with HQL, but I also need to conditionally change the query which is perfect for criteria. I suppose I could put a...

How to map inheritance with property returned other inheritance?

Hi I have abstract class Vehicle and two classes that derive from: Car and ForkLift. public abstract class Vehicle { public EngineBase Engine { get; set; } } public class Car : Vehicle { public GasEngine Engine { get; set; } } public class ForkLift : Vehicle { public ElectricEngine Engine { get; set; } } and Engine clas...

Querying a self referencing join with NHibernate Linq

In my application I have a Category domain object. Category has a property Parent (of type category). So in my NHibernate mapping I have: <many-to-one name="Parent" column="ParentID"/> Before I switched to NHibernate I had the ParentId property on my domain model (mapped to the corresponding database column). This made it easy t...

Inheritance - Could not initialize proxy - no Session.

hello....i'm newbie developer.... i really need help at now... i just get started with Nhibernate thing at .Net... when i learn Inheritance and try it...it makes me confusing...why i get error like this : Initializing[AP.Core.Domain.AccountPayable.APInvoice#API03/04/2010/001]-Could not initialize proxy - no Session. this is my xml : ...

Nhibernate not tracking changes

I'm using nhibernate and it appears that changes to my new object are not persisted. After creating and saving an object I then modify it and commit the transaction. However none of the modifications are saved. The strange thing is this code was working previously and I have no idea what could cause this. Nothing was changed that's obvio...

Step by step(screen shots) setup of nhibernate with asp.net mvc...

I am interested in looking for Step by step(screen shots) setup of nhibernate with asp.net mvc.... Any good links would be really useful... ...

Nhiberate, multiple tables, same class

It's been asked a million times, its like this. Say Invoice is the base class and InvoiceHistory is the class that simply inherits from Invoice. When I do something like invoiceList = session.CreateCriteria(typeof(Invoice)).List(); I get everything from Invoice (that I want, plus everything from InvoiceHistory). Do I need to have an ...

How to eager fetch a child collection while joining child collection entities to an association

Assuming the following fictional layout Dealership has many Cars has a Manufacturer I want to write a query that says get me a Dealership with a Name of X and also get the Cars collection but use a join against the manufacturer when you do so. I think this would require usage of ICriteria. I'm thinking something like this.. ...

Is there a comprehensive list of the NHibernate event listeners and when they actually fire?

So I am looking for a nice list of NHibernate events that actually describes when they are fired, in a typical scenario (not just a list). IE something like PreUpdateEventListener - Fires when an object that is already persistent is changing I currently just rifle through the source and try to figure it out, but it's kinda pai...

Is it possible to unit test methods that rely on NHibernate Detached Criteria?

I have tried to use Moq to unit test a method on a repository that uses the DetachedCriteria class. But I come up against a problem whereby I cannot actually mock the internal Criteria object that is built inside. Is there any way to mock detached criteria? Test Method [Test] [Category("UnitTest")] public void F...

NHibernate Criteria Transform Result

Hi I have an SecurityGroup entity witch has Memebers and Application properties. Application is a lookup. So securityGroups is in many-to-many relationship with User table and one-to-many with LookupApplciation (FK) Now I want to select all application linked to a specific user. I have follow criteria: public IList<LookupApplicatio...

Fine tune some SQL called multiple times

Hi all, I currently have an SQL query which is currently called multiple times like this (pseudo code): foreach(KeyValuePair kvp in someMapList) { select col1 from table where col2 = kvp.key and col3 = kvp.value; //do some processing on the returned value } The above could obviously call the database a large number of times if...

NHibernate HiLo generation and SQL 2005/8 Schemas

I have an issue on my hands that I've spent several days searching for an answer to no avail... We're using HiLo Id generation, and everything seems to be working fine, as long as the entity table is in the same schema as the hibernate_unique_key table. The table structure is pretty simple. I have my hi value table in the db as dbo.hib...

NHibernate with multiple databases and transactions

We are having a few problems understanding how best to use NHibernate. We typically have a relatively large number of quite small (in terms of number of tables) SQL Server databases rather than one database with a lot of objects. We are looking at various options for handling multiple session factories and probably have this under cont...