表值函数和Entity Framework [英] Table Valued Function and Entity Framework

查看:183
本文介绍了表值函数和Entity Framework的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图执行与实体框架和出于某种原因,它只是不工作的TVF。
也许有任何人可以帮我看看这个问题。

I'm trying to execute an TVF with Entity Framework and for some reason it just doesn't work. Maybe anyone out there can help me see the problem.

下面是示例代码:

这就是功能:

CREATE FUNCTION [dbo].[udf_profileSearch]
(@keywords NVARCHAR(3000))
RETURNS @results TABLE 
(
    [Id] [int] NULL,
    [SubCategoryId] [int] NULL,
    [UserId] [int] NULL,
    [SmallDescription] [nvarchar](250) NULL,
    [DetailedDescription] [nvarchar](500) NULL,
    [Graduation] [nvarchar](140) NULL,
    [Experience] [nvarchar](500) NULL,
    [IsChat] [bit] NULL,
    [IsEmail] [bit] NULL,
    [MinuteCost] [decimal](18, 2) NOT NULL,
    [TestimonyRate] [int] NULL,
    [TestimonyQuantity] [int] NULL,
    [StatusId] [int] NULL
)

AS
BEGIN
IF(@keywords != '')
    BEGIN
        insert @results
            SELECT p.Id, p.SubCategoryId, p.UserId, p.SmallDescription, p.DetailedDescription, p.Graduation, 
                        p.Experience, p.IsChat, p.IsEmail, p.MinuteCost, p.TestimonyRate, p.TestimonyQuantity, 
                        p.StatusId FROM 
            Profile p inner join ProfileSearchKeyword psk
            ON p.Id = psk.ProfileId
            WHERE CONTAINS(psk.*,@keywords)
    END
ELSE 
    BEGIN
        insert @results
            SELECT p.* FROM 
            Profile p inner join ProfileSearchKeyword psk
            ON p.Id = psk.ProfileId
    END
RETURN
END

我有这在我的DbContext文件(名为EAjudaContext)

I have this in my DbContext file (named EAjudaContext)

[EdmFunction("eAjudaConnection", "udf_profileSearch")]
    public virtual IQueryable<Profile> udf_profileSearch(string keywords)
    {
        var keywordsParameter = keywords != null ?
            new ObjectParameter("keywords", keywords) :
            new ObjectParameter("keywords", typeof(string));

        return ((IObjectContextAdapter)this).ObjectContext.CreateQuery<Profile>("eAjudaConnection.udf_profileSearch(@keywords)", keywordsParameter);
    }



这就是我如何打电话通过LINQ的FUNC

That's how I'm calling the func via LINQ

var result = from ps in eAjudaCtx.udf_profileSearch("query") select ps

和我得到这个错误:

And I get this error:


'eAjudaConnection.udf_profileSearch' cannot be resolved into a valid type or function.

这是我缺少的是什么我任何想法?
我已经试过几乎每一个提示,我在谷歌找到,但没有解决我的问题。

Any ideas on what I'm missing? I've tried pretty much every tip I found on google, but none solved my problem.

如果你需要看到任何一段代码这里不包括,只问我会添加它。

If you need to see any piece of code not included here, just ask and I'll add it.

推荐答案

下面是在提供实体框架的新功能一篇很好的文章为表值UDF的直接支持。上表值函数 MSDN博客支持实体框架。

Here is a very good article on the newer features of Entity Framework that provide direct support for Table Valued UDFs. MSDN blog on Table-Valued Function Support in Entity Framework.

有关更深入,本文提供了显著的细节。 EDM并暴露在LINQ存储功能。

For greater depth, this article provides significant detail. EDM and store functions exposed in LINQ.

一对表值的UDF最近支持的巨大优势包括为全文搜索功能的支持。了解更多关于在这里:​​全部涉及文本搜索功能数据库对象。

One of the great advantages of the recent support for Table-Valued UDFs involves support for Full-Text Search capabilities. Read more about that here: Full text search features involving database objects.

这篇关于表值函数和Entity Framework的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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