nhibernate审计查询

发布于 2024-11-06 21:54:29 字数 369 浏览 0 评论 0原文

我在我的项目中使用 NHibernate,并使用事件侦听器实现了审核功能。

我现在需要取回这些数据,我想完全按照数据库中的情况返回它,我不需要带有关系的丰富对象模型,我想要的只是任何关系的 ID。

我基本上只是想显示一个审核日志(它本质上是您在 sql 中打开表时看到的内容的副本)。

我需要能够对许多表执行此操作,而我所拥有的只是审核表名称,是否有一种通用方法可以让 NHibernate 查询表并仅将结果作为数据表或类似的简单方法返回没有定义的模型吗?

所以本质上我希望 NHibernate 这样做:

SELECT * FROM "tablename"

然后以某种通用的方式返回它,我可以将其放入网格中并让它自动生成列。

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 audit 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨落成白 2024-11-13 21:54:29

您可以使用以下命令来查询未映射的对象。

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

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

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/

生活了然无味 2024-11-13 21:54:29

您可以使用“select”方法仅获取所需的字段:

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

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});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文