使用存储在实体框架5与复杂类型的程序? [英] Using stored procedure in Entity Framework 5 with complex type?

查看:156
本文介绍了使用存储在实体框架5与复杂类型的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL Server中的以下存储过程:

I have the following stored procedure in SQL Server:

ALTER PROCEDURE [dbo].[FullTextSearchOnContent]
(
    @SearchText NVARCHAR(200),
    @LanguageId INT ,
    @ContentStatusId INT ,
    @ResultCount INT 
)
AS

BEGIN
    SET FMTONLY OFF;
    SET NOCOUNT ON;
    IF (@SearchText IS NULL) OR (@SearchText = '') OR (@ResultCount IS NULL) OR (@ResultCount = 0) RETURN NULL;
    SELECT DISTINCT TOP(@ResultCount) 
        C.Id AS ContentId, C.ImagePath AS ContentImagePath, C.IsSpecial,C.LanguageId,C.LockCommenting,C.RegistrationDate AS ContentRegistrationDate,C.StatusId AS ContentStatusId,C.Summary,C.Title,C.VisitNumber,C.AllTagsString,
        CS.FarsiName AS ContentStatusFarsiName,
        U.Id As UserId,U.InitialReputation AS UserInitialReputation,U.IsAdmin AS IsUserAdmin,U.FullName AS UserFullName,U.PhotoPath AS UserPhotoPath,U.RoleId AS UserRoleId,U.UserStatusId AS UserStatusId
        --,T.Id AS TagId, T.Name AS TagName
        FROM Content AS C
    INNER JOIN [User] AS U ON U.Id = C.WriterId
    INNER JOIN [Subject] AS S ON S.Id = C.SubjectId
    INNER JOIN [ContentStatus] AS CS ON CS.Id = C.StatusId
    --INNER JOIN (SELECT DISTINCT * FROM Tag AS T
    --          INNER JOIN TagContent AS TC ON TC.TagId=T.Id) 
    --          AS T ON T.ContentId = C.Id
    WHERE C.LanguageId = @LanguageId AND C.StatusId=@ContentStatusId AND CONTAINS((C.Title,C.AllTagsString),@SearchText) ORDER BY C.RegistrationDate DESC
END

它用于一些列的全文检索。

It's used for fulltext search on some columns.

我想在EF5使用它,但它总是返回 INT

I want to use it in EF5, but it always returns int!

我可以如何在实体框架5使用

How can I use it in Entity Framework 5 ?

编辑:

我做不到生成COMLEX类型,每当我点击获取列信息按钮没有发生!

I couldn't generate the comlex type, whenever I click on Get Column Information button nothing happen !

推荐答案

我刚刚找到了答案

我已经改变了存储过程如下:

I just found The answer.
I've changed the stored procedure as the following :

ALTER PROCEDURE [dbo].[FullTextSearchOnContent]
(
    @SearchText NVARCHAR(200),
    @LanguageId INT ,
    @ContentStatusId INT ,
    @ResultCount INT 
)
AS

BEGIN
    SET NOCOUNT ON;

    DECLARE @ReturnTable table 
    (
        ContentId int not null,
        LanguageId int null,
        ContentStatusId int null,
        ContentTitle nvarchar(2000) null,
        ContentSummary nvarchar(2000) null,
        ContentImagePath nvarchar(50) null,
        IsSpecial bit null,
        LockCommenting bit null,
        VisitNumber int null,
        AllTagsString nvarchar(max) null,
        ContentRegistrationDate datetime not null,
        ContentStatusFarsiName nvarchar(50) null,
        UserId int null,
        UserInitialReputation int null,
        IsUserAdmin bit null,
        UserFullName nvarchar(71) null,
        UserPhotoPath nvarchar(50) null,
        UserRoleId int null,
        UserStatusId int null,
        SubjectId int not null,
        SubjectName nvarchar(50) null,
        SubjectSymbolPath nvarchar(1000) null
    )
    IF (@SearchText IS NULL) OR (@SearchText = '') OR (@ResultCount IS NULL) OR (@ResultCount = 0) RETURN NULL;
    INSERT @ReturnTable 
        SELECT DISTINCT TOP(@ResultCount) 
            C.Id AS ContentId, 
            C.LanguageId,
            C.StatusId AS ContentStatusId,
            C.Title AS ContentTitle,
            C.Summary AS ContentSummary,
            C.ImagePath AS ContentImagePath, 
            C.IsSpecial,
            C.LockCommenting,
            C.VisitNumber,
            C.AllTagsString,
            C.RegistrationDate AS ContentRegistrationDate,
            CS.FarsiName AS ContentStatusFarsiName,
            U.Id As UserId,
            U.InitialReputation AS UserInitialReputation,
            U.IsAdmin AS IsUserAdmin,
            U.FullName AS UserFullName,
            U.PhotoPath AS UserPhotoPath,
            U.RoleId AS UserRoleId,
            U.UserStatusId AS UserStatusId,
            S.Id AS SubjectId,
            S.Name AS SubjectName, 
            S.SymbolPath AS SubjectSymbolPath
            --,T.Id AS TagId, T.Name AS TagName
            FROM Content AS C
        INNER JOIN [User] AS U ON U.Id = C.WriterId
        INNER JOIN [Subject] AS S ON S.Id = C.SubjectId
        INNER JOIN [ContentStatus] AS CS ON CS.Id = C.StatusId
        --INNER JOIN (SELECT DISTINCT * FROM Tag AS T
        --          INNER JOIN TagContent AS TC ON TC.TagId=T.Id) 
        --          AS T ON T.ContentId = C.Id
        WHERE C.LanguageId = @LanguageId AND C.StatusId=@ContentStatusId AND CONTAINS((C.Title,C.AllTagsString),@SearchText) ORDER BY C.RegistrationDate DESC
    select * from @ReturnTable
    --SELECT TOP(@ResultCount) * from Content order by RegistrationDate desc
END

现在它就像一个魅力: - )

Now it works like a charm :-)

这篇关于使用存储在实体框架5与复杂类型的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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