tags:

views:

448

answers:

2

Is it possible to do a mapping in NHibernate without using an Id?

What I'm trying to do is, call a stored procedure using

session.CreateSqlQuery( myQuery ).AddEntity( typeof( MyEntity ) );

The procedure is an aggregate and there is no Id field being returned, but I would still like to take advantage of NHibernate mapping the data returned into an entity. The only thing I have come up with so far is having the procedure add a field "O as Id" or something, and have the entity have a fake Id field.

A: 

I need to double-check the xsd, but I believe either id or composite-id are required. However, per the docs, name isn't required. So, you should be able to specify an almost-blank id section.

In a similar situation, I've set the class to mutable="false" and mapped the id to the row index and set the generator in the id mapping to assigned.

Ben
Okay - dumb question. How does one map to the row index? What does that look like in the mapping file? We looked for this in the documentation and decided to ask.
ferventcoder
A: 

I found this really isn't possible. The data returned from the stored procedure has to have an Id also. It worked to just create a dummy column with an Id, and a dummy property on the object, but I just decided to convert the data returned by NHibernate to an object by hand.

Basically, you're not supposed to use stored procedures with NHibernate. It IS an ORM afterall. In my case, I had no choice but to use the procedure.

Josh Close