Sofija
Sofija

Reputation: 723

Using NHibernate to insert into view

If one would want to insert into a view, what would be required to setup on NHibernate to allow this.

Neither

<generator class="identity" />

nor

<generator class="native" />

allows insert.

Error I get when I try this is either "Null id" or "Null identifier".

Upvotes: 0

Views: 820

Answers (2)

Rippo
Rippo

Reputation: 22424

I have never done this but have you tried assigned:-

<generator class="assigned" />

Any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table.

See here MSDN for more info

And there is one more thing if you use assigned, you have to explicitly specify to NHibernate if the object should be saved or updated by calling either the Save() or Update() method of the ISession.

Upvotes: 1

Mr Mush
Mr Mush

Reputation: 1538

You can not insert, update or delete from a view even with regular SQL commands, nor with NHiberanate. Views are designed for read only purposes. You should model your class from the original tables in a similar fashion as the view and then you could do any CRUD operation on it.

Upvotes: 1

Related Questions