Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does NHibernate support mapping from SQL Views?

Does NHibernate support mapping of SQL VIEWS? Any examples would be helpful.

like image 951
vikram nayak Avatar asked Dec 07 '22 01:12

vikram nayak


2 Answers

Yes, just use your view name instead of the table name in your mapping config. Of course it will throw an exception if you try to update though.

e.g.:

<class name="someclass" table="vw_someview">
...
</class>
like image 110
UpTheCreek Avatar answered Dec 09 '22 13:12

UpTheCreek


Yes. You can update or insert to views in SQL Server if certain conditions are met, see the Updateable Views section in the documentation. I know this applies to SQL Server 2005+, I don't know about earlier versions.

If the view is not updateable, you can declare the mapping as read-only.

like image 22
Jamie Ide Avatar answered Dec 09 '22 15:12

Jamie Ide