Create Database Views by Nhibernate by code

608 views
Skip to first unread message

Amar Kulkarni

unread,
Feb 9, 2012, 7:18:24 AM2/9/12
to nhusers
Hello,

By mapping Entity class we are able to create the database tables by
using Conventional Model Mapper and Class Mappings.
But there is no provisioning for create the view .
I know that Nhiberate Maps the Existing database view with the Entity
Class,But unable to create the New View in database instead of Table.

Any Idea to tell ConventionalModelMappper or anything in Nhibernate by
code to Create View for the Entity Class..


Thank You

Amar

Itzik Saban

unread,
Feb 9, 2012, 7:43:57 AM2/9/12
to nhusers
Hi Amar,

I don't know about ConventionalModelMappper (never heard about it...),
but if you're using hbm files along with SchemaExport, then you can do
this in your hbm file:

<class name="SomeClass" table="MY_VIEW" schema-action="none">
.....
.....
.....
</class>
<database-object>
<create>
CREATE VIEW MY_VIEW ("ID", "DESCRIPTION"...) AS
select "CODE" as id ,"DESCRIPTION" FROM SOME_TABLE
where ....
</create>
<drop>DROP VIEW MY_VIEW</drop>
</database-object>
Reply all
Reply to author
Forward
0 new messages