nhibernate

NHibernate: generic way of getting number of lines returned by arbitrary criteria query

I know about CriteriaTransformer.TransformToRowCount but according to link and my experience it doesn't work with aggregate functions (and they used quite often). Since I'm writing kinda paging framework for my app it would be very tedious to write "count" query for every data query. Any ideas how this can be optimized? ...

NHibernate HQL - select count(*) with having - can't get it to work

Trying to run the following HQL with NHibernate: select count(distinct t) as TweetCount from Tweet t join t.Tweeter u left join t.Votes v left join t.Tags tag where t.App = :app having count(distinct v) > 0 But for some reason the having clause is being ignored and it's counting all tweets when only 2 tweets have a vote. I...

Why is Fluent NHibernate ignoring my convention?

Here is a small VS 2010 solution with a single failing test that replicates the following issue. I have a convention UserTypeConvention<MyUserType> where MyUserType : IUserType where MyUserType handles an enum type MyEnum. I have configured Fluent NHibernate thusly sessionFactory = Fluently .Configure() ...

Nhibernate Update does not persist change to database

I have a problem getting my change(s) to data object retrieved using NHibernate to persist back into the database. I get no exceptions so it's difficult to know where to look. Any suggestions? string name = "somenewname"; string repositoryId = "somerepositoryid"; ISession nhbSession = GetNhbSession(session); nhbSession.Transaction.Begi...

Are nhibernate entities part of the BL?

Hi all, I am looking for the right n-tier modal to adapt to my new nhibernate project. I am quite new to it. I currently have several entities and their corrosponding mapping classes. I can't seem to figure if the entities should act as the BL level classes, or merly an object oriented part of my DAL. Can anyone help shed light on this...

Remove entity in NHibernate only by primary key

I'm trying to implement a repository method for removing entities using only primary key, mainly because from a webapp I usually only are aware of the primary key when invoking a "delete request" from a web page. Because of the ORM, the option today is to get the entity from the database, and then deleting it, which gives me an extra ro...

I am getting a "duplicate association path" error in the NHibernate Criteria when accessing the same table twice.

I have a CreateCriteria that adds a join to the same table twice with different aliases: aCriteria.CreateCriteria("Color", "co").Add(Expression.In("co.ColorId", bikush.Color.Select(x => x.ColorId).ToList())); aCriteria.CreateCriteria("Color","fco").Add(Expression.In("fco.ColorId",bikush.FCColor.Select(x => x.ColorId).ToList())); I'm...

CRUD Update, changing entity relationship with dropdown using ASP.NET MVC 2, and NHibernate

I'm running into a few problems with CRUD Update (Edit) scenarios where an entity relationship is altered via drop down list of possible entities, using ASP.NET MVC and NHibernate. Probably I am just doing something stupid, so I was wondering if someone could give me a quick example of how this should be done, as I haven't been able to ...

can you re-use nhibernate mapping files for tables with common columns

We have a bunch of lookup tables that all share the same columns (ID,Code,Description, etc) and my co-worked just asked me if we could build a generic lookup.hbm.xml mapping file and use it as a base for all the other lookup tables. Does nhibernate support include files, or some other way to reference a common chunk of XML? I understan...

Dependencies in Acceptance Testing

Me and a co-worker are having a debate. We are on a craptastic legacy project and are slowly adding acceptance tests. He believes that we should be doing the work in the gui/watin then using a low level library to query the database directly for to get an 'end to end' test as he puts it. We are using NHibernate and I advocate using gui...

Is there an ASP.NET MVC book which uses NHibernate for ORM?

I'm learning ASP.NET MVC but I prefer to use OS X and MonoDevelop(especially Mono 2.8 is out now, supports ASP.NET MVC 2). Is there an ASP.NET MVC book that also teach how to use NHibernate and Postgresql or MySQL? (No Sql Server, as that would entail me installing vmware/parallels in OS X) ...

Implement a "cancel" button on forms that use databinding and nhibernate

Hello all I use nhibernate to access a mysql database, and I have many -winforms- forms using databinding to modify properties of those objects. There are many –nhibernate- objects created/deleted also during the time those forms are used. I need to implement a "Cancel" button on those forms. I can defer the creation/deletion of objec...

IsessionFactory Issue

I am getting the classic "object reference not set to an instance of a object" error on this line HttpContext.Items["ISession"] = Configure.GetSessionFactory().OpenSession(); My configure.cs file is as follows using System; using System.Collections.Generic; using System.Linq; using System.Text; using FluentNHibernate.Cfg; using Fluen...

Changing part of a composite-id

I have a class, BillMedicine, which is many-to-many table for Bill and Medicine. The BillMedicine mapping file is: <class name="BillMedicine" table="Bill_Medicine"> <composite-id> <key-many-to-one name="Bill" class="Bill" column="BillID" /> <key-many-to-one name="Medicine" class="Medicine" column="MedicineID" /> ...

Remove from one side of the many to many in Nhibernate

Hi there, I have these 2 objects in NHibernate forming a many to many relationship: User: <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Providers" namespace="Providers.Objects"> <class name="User" table="Users"> <id name="UserId" type="int"> <ge...

How do I get NHibernate to save an entity if I assign it an ID, but generate one otherwise?

According to the REST philosophy, a PUT request should update the resource at a URL if it exists, and create it if it doesn't exist. So in other words, if I use the following URL: PUT http://server/item/5 If an Item exists with an ID of 5, it will be updated. If an Item doesn't exist with an ID of 5, a new Item will be created with an...

NHibernate Component Mapping VS IUserType

Hi I would like to know the difference between the two and why should you use one over the other and when? Thnaks ...

Adding and saving not persistent objects to persistent object in NHibernate

Could someone explain this for me? I have standard relations in my MSSQL DB: [item] id symbol [item_version] id item_id (fk) symbol In [item] mapping there is a standard item_version BAG with cascade="all" and many-to-one in [item_version] mapping. This is the test case: [Test] public void AddNewVersionToPersistentObject(...

SetFetchMode call ignored

I have a problem with SetFetchMode call in Criteria API in following query: DetachedCriteria.For<User>() .Add<User>(u => u.Status == UserStatus.Live) .CreateAlias("UniqueId", "uid") .CreateAlias("Companies", "comp") .Add(Restrictions.Disjunction() ...

newbie Nhibernate join query in a DetachedCriteria

I have a domain like this: class Project { ... Unit ProjectUnit } class Unit { ... IList<User> Users } class User { ... } I have to get all projects based on one user, so: each Project where Unit.Users contain query user. How can I translate this to a DetachedCriteria? ...