如何将 Linq 与 Castle ActiveRecord 一起使用 [英] How to use Linq with Castle ActiveRecord

查看:18
本文介绍了如何将 Linq 与 Castle ActiveRecord 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩 Castle ActiveRecord 并注意到下载中包含文件 Castle.ActiveRecord.Linq.dll.我还没有找到将 Linq 与 ActiveRecord 结合使用的任何文档,只有 一些 博客文章.

使用模式是什么?Castle.ActiveRecord.Linq 准备好用于生产了吗?

解决方案

是的,Castle.ActiveRecord.Linq 已准备好投入生产.它包含在最新的 ActiveRecord 版本中.实际的 Linq 提供程序在 NHibernate.Linq.dll 中实现,ActiveRecord Linq dll 是一个薄的传递层.基本上有两种使用方式:

  1. 让你的实体从 ActiveRecordLinqBase 继承,然后查询:

    var blogs = (from b in Blog.Queryable select b).ToList();

  2. 使用ActiveRecordLinq.AsQueryable,例如:

    var blogs = (from b in ActiveRecordLinq.AsQueryable() select b).ToList();

查看测试 一些示例代码.

更新:从 ActiveRecord 3.0 beta 开始,Linq 集成到 Castle.ActiveRecord.dll 中,NHibernate.Linq.dll 不再存在(从 NHibernate 3 开始集成到 NHibernate.dll)

I am playing around with Castle ActiveRecord and noticed that the download included the file, Castle.ActiveRecord.Linq.dll. I haven't found any documentation for using Linq with ActiveRecord, only some old blog posts.

What is the usage pattern? Is Castle.ActiveRecord.Linq ready for production use?

解决方案

Yes, Castle.ActiveRecord.Linq is production ready. It's included in the latest ActiveRecord release. The actual Linq provider is implemented in NHibernate.Linq.dll, the ActiveRecord Linq dll is a thin pass-through layer. There are basically two ways to use it:

  1. Make your entities inherit from ActiveRecordLinqBase<T>, then to query:

    var blogs = (from b in Blog.Queryable select b).ToList();
    

  2. Use ActiveRecordLinq.AsQueryable<T>, e.g.:

    var blogs = (from b in ActiveRecordLinq.AsQueryable<Blog>() select b).ToList();
    

Look at the tests for some sample code.

UPDATE: as of ActiveRecord 3.0 beta, Linq is integrated into Castle.ActiveRecord.dll, and NHibernate.Linq.dll is no more (integrated into NHibernate.dll as of NHibernate 3)

这篇关于如何将 Linq 与 Castle ActiveRecord 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆