在实体框架中使用动态 where 子句
我正在尝试重新设计最初使用 Raptier 构建的数据访问层。 Raptier 生成的方法接受 where 子句作为要传递到存储过程的参数。我确实需要保留现有的 mesthos 签名,因此我的新 DAL 也需要接受 where 子句。我想使用更最新的数据访问技术和技巧,因此正在考虑使用.Net 4.0 中的实体框架。
然而,看起来我不能接受动态 where 子句而不实现一些密集的重新例程来将它们解析为巴表达式。有什么我错过的吗?我对实体框架运气不好吗?
谢谢, 马克
I am trying to re-design a data access layer that was originally built using Raptier. Raptier generats methods that accept a where clause as a parameter to be passed in to a stored proc. I really need to retain the existing mesthos signatures, so my new DAL needs to accept where clauses as well. I want to use the more up-to-date data access technologies and techniques, so was thinking about using Entity Framework from .Net 4.0.
However, it doesn't look like I can accept dynamic where clauses without implementing some intense reoutines to parse them into lamba expressions. Is there something I've missed? Am I out of luck with Entity Framework?
Thanks,
Marc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我想到了两个想法。
1). 动态 LINQ,它允许您将 where 运算符定义为字符串。
2)。使用某些内容作为
EntityFilter
(请参阅代码此处< /a>),它允许您定义如下过滤器:您可以将
IEntityFilter
提供给能够过滤该查询的业务方法:Two ideas come in mind.
1). Dynamic LINQ, which allows you to define where operators as strings.
2). Use something as the
EntityFilter<T>
(see code here), which allows you to define a filter like this:You can supply the
IEntityFilter<Person>
to a business method that will be able to filter that query:您可以使用 ExecuteStoreQuery 方法对数据库执行原始命令。
http://msdn.microsoft.com/en-us/library/ee358769.aspx
You can use ExecuteStoreQuery method to execute raw commands against the database.
http://msdn.microsoft.com/en-us/library/ee358769.aspx
请在此处查看 Rick Strahl 的博客文章:http://www.west-wind.com /weblog/posts/160237.aspx。他的演示使用 Linq to SQL,但在 EF 中不会有太大不同。此方法涉及将 IQueryable 暴露给业务层。这并非没有争议,但值得考虑。
通过公开 IQueryable,您可以针对返回的集合编写 LINQ 查询。我不保证您能够使其与存储过程一起工作,但请尝试一下。
Check out Rick Strahl's blog post here: http://www.west-wind.com/weblog/posts/160237.aspx. His demo uses Linq to SQL but it wouldn't be far different in EF. This approach involves exposing the IQueryable to the business layer. It is not without controversy, but it's something to consider.
With the IQueryable exposed, you can write LINQ queries against the returned collection. I'm not promising that you'll be able to make it work with sprocs, but give it a try.
面临同样的问题,现在 raptier 可能已经停产了,所以
我有一个线索,因为我使用的是仅支持 15 个表/视图的精简版。
这是一个捷径,
总是在服务器中获取一个虚拟测试数据库,并生成您想要的类,然后将其与您的类库解决方案合并,重建解决方案,然后继续进行到您想要的程度, ,
它很费力,但它的工作。
需要更多帮助,很高兴...
face same problem,, now the raptier discontinued might be,, well so
i have a clue,, as i am using lite version which support only 15 tables/views..
here is a short cut,,
always take a dummy test db in the server,, and generate the classes which you want, then merge it with your class library solution, rebuild the solution, and move on like that to the extent you want,,
its laborious but its work.
need more help,, with glad...