开发者

nhibernate audit query

开发者 https://www.devze.com 2023-03-05 07:49 出处:网络
I\'m using NHibernate on my project and have implemented auditing functionality using event listeners.

I'm using NHibernate on my project and have implemented auditing functionality using event listeners.

I now need to get this data back, I want to return it exactly as it is in the database I dont need a rich object model with relationships all I want is the IDs of any relationships.

I am basically just trying to show an audit log (which is essentially a copy of what you would see if you opened the table up in sql).

I need to be able to do this for many tables though and all I have is the au开发者_开发问答dit table name, is there a generic way to get NHibernate to query a table and just return the results as a datatable or something simple like that that doesn't have a defined model?

So essentially I want NHibernate to do this:

SELECT * FROM "tablename"

and then return it in some generic way that I can put in a grid and have it autogenerate the columns off it.


You could use the following to query unmapped objects.

string tablename = "nonmapped";
IList<Unmapped> result = session
                                .CreateSqlQuery("select Id, Description from " + tablename)
                                .SetResultTransformer(Transformer.AliasToBean(typeof(Unmapped)))
                                .List<Unmapped>();

More: http://lostechies.com/jimmybogard/2010/06/30/ad-hoc-mapping-with-nhibernate/


you can use the 'select' method to get only the fields you want:

session.CreateCriteria(typeof(Cat)).Select(c=> new {Id = c.Id, MateId = c.Mate.Id});
0

精彩评论

暂无评论...
验证码 换一张
取 消