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.
Your entity must be "unique" in some way, even if it doesn't have an Id field.
Decide which properties, when taken together, must be unique, and use a composite key over them...
<composite-id>
<key-property name="Property1" column="Column1"/>
<key-property name="Property2" column="Column2"/>
</composite-id>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With