Sqlserver
 sql >> Baza danych >  >> RDS >> Sqlserver

Używasz procedury składowanej w Entity Framework 5 z typem złożonym?

Właśnie znalazłem odpowiedź.
Zmieniłem procedurę składowaną w następujący sposób:

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 [email protected] 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

Teraz działa jak czar :-)




  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Problemy z wydajnością parametru wartości tabeli

  2. Używając z vs deklaruj tabelę tymczasową:wydajność / różnica?

  3. Jak napisać .Skip(1000).Take(100) LINQ w czystym SQL?

  4. Automatyzacja defragmentacji indeksów w bazie danych MS SQL Server

  5. Przekroczono poziom zagnieżdżenia wyzwalacza?