views:

47

answers:

2

Does any one know how to create a view from hibernate with the results of a criteria query?

We've got some legacy parts of our application that use views generated by the app for data retrieval and I like to tie the new NHibernate stuff into those for minimal friction.

I'd turn it into an extension method so I could eventually do stuff like this:

session.CreateCriteria<Thing>().CreateReportView().List();

Any ideas?

The existing process is like this:

SQLString = _bstr_t("SELECT name FROM User WHERE Retired = false");

...run the query process the results, then...

SQLStringView = _bstr_t(" \
  BEGIN EXECUTE IMMEDIATE 'CREATE OR REPLACE VIEW ") + ViewName + _bstr_t(" AS ") + SQLString;

So whenever we run this query we get a view that has the same data in it. I can't work out how to replicate this is hibernate though.

A: 

If you're only interested in filtering the data being returned, you may want to have a look at Nhibernate's filtering mechanisms; here is a good article outlining their usage.

DanP
Matt Sharpe
A: 

Check out this article for an explanation of mapping an entity class to a view and a table. I'm not certain that you'll be able to dynamically create your views at runtime as you specified; but perhaps this can be done as part of the schema generation process using the database-object mapping?

DanP