使用 Linq to Entities 存储函数

发布于 2024-09-04 05:46:43 字数 254 浏览 2 评论 0原文

如果使用实体框架,如何在 LINQ 表达式中使用 MS-SQL 存储函数?

SQL 函数是使用 CREATE FUNCTION MyFunction(@name) ...) 创建的。我希望以类似的方式访问它:

var data = from c in entities.Users where MyFunction(c.name) = 3;

不幸的是我只有 .NET 3.5 可用。

How can I make a MS-SQL stored function availabe in LINQ expressions if using the Entity framework?

The SQL function was created with CREATE FUNCTION MyFunction(@name) ...). I was hoping to access it similarly to this:

var data = from c in entities.Users where MyFunction(c.name) = 3;

Unfortunately I have only .NET 3.5 available.

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

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

发布评论

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

评论(1

锦欢 2024-09-11 05:46:44

您实际上可以 在 EF 1 中导入数据库函数。但是,您在 EF 1 中无法获得 EdmFunctionAttribute,因此您仅限于可以使用它们的上下文。为此,您需要 EF 4。

对于您的情况,您可能需要考虑映射一个返回 Users 的过程(对于 3.5;同样,4 更适合此功能)。

You actually can import DB functions in EF 1. But you don't get EdmFunctionAttribute in EF 1, so you're limited to the contexts where you can use them. You need EF 4 for that.

For your case you might want to consider mapping a proc returning Users (for 3.5; again, 4 is better for this feature).

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