是否可以将SQL级功能提供给LINQ to Entity查询? [英] Can SQL level functions be made available to LINQ to Entity queries?

查看:52
本文介绍了是否可以将SQL级功能提供给LINQ to Entity查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我可以将LINQ写入调用其他功能的实体查询:

I wish I could write LINQ to Entity queries that called other functions:

from c in context.Widgets
where MyFunc(c.name)
select c

这会导致错误,因为表达式显然无法转换为调用MyFunc的TSQL。

That causes an error because the expression obviously can't be converted to TSQL that calls MyFunc.

好吧,我在想,除非MyFunc是用户定义的函数或(我认为更好) SQL / CLR函数。

Well, I'm thinking, unless MyFunc was either a user defined function or (I think better yet) a SQL/CLR function.

那么这是可能的,而且建议这样做吗?

So is this possible, and moreover is it recommended?

如果不可能,我是否想让此功能有效,是否可能由ADO.NET的将来解决?

If it's not possible, is my desire to have this feature valid and possibly going to be addressed by a future of ADO.NET?

推荐答案

您应该在数据库中创建用户定义的函数 MyFunc 并将其手动导入到您的数据库中上下文(edmx,数据库优先),在XML中以及作为上下文类的局部类中的存根。此处描述了该过程:

You should create a user-defined function MyFunc in the database and "import" it manually into your context (edmx, so database first), both in the XML and as a stub in a partial class off the context class. The procedure is described here:

如何使用自定义数据库功能(请注意, StorageNamespace是您在XML中找到的名称空间< edmx:StorageModels>< Schema命名空间= ... 下的文件。

How to use a custom database function (Note that "StorageNamespace" is the namespace that you find in the XML file under <edmx:StorageModels><Schema Namespace=....

MSDN 具有类似的描述。

这篇关于是否可以将SQL级功能提供给LINQ to Entity查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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