1

I'm new to using SQL server free text indexes. I've written a query that I'd like to convert to EF Core Linq query.

I'm not if it possible or not (if not I'll create a stored procedure), but ideally I'd like to construct it in C# as a few other queries will be more dynamic than this one, and id rather not have multiple stored procedures.

Here is the query:

declare @searchTerm varchar(50) = '16 Sorrento';
declare @postcode varchar(50) = 'CF10 4AR';
declare @language varchar(3) = 'ENG';
declare @offset int = 0;
declare @limit int = 100;

select 
    RankTotal = isnull(RankSAONDetails, 0) + isnull(RankPAONDetails, 0) + 
                isnull(RankStreet, 0) + isnull(RankWard, 0) + 
               isnull(RankPostcode, 0),
    Id, UPRN, ParentUPRN, USRN, SAONDetails, PAONDetails, 
    Street, Ward, PostTown, Postcode, Easting, Northing, 
    Usage, Language, LastUpdateDate, DateExtracted
from
    LLPG
left join 
    (select Rank * 3.0 as RankSAONDetails, [KEY] 
     from FREETEXTTABLE(LLPG, SAONDetails, @searchTerm)) as k on k.[key]= LLPG.Id
left join 
    (select Rank * 4.0 as RankPAONDetails, [KEY] 
     from FREETEXTTABLE(LLPG, PAONDetails, @searchTerm)) as l on l.[key]= LLPG.Id
left join 
    (select Rank * 3.0 as RankStreet, [KEY] 
     from FREETEXTTABLE(LLPG, Street, @searchTerm)) as m on m.[key]= LLPG.Id
left join 
    (select Rank * 3.0 as RankWard, [KEY] 
     from FREETEXTTABLE(LLPG, Ward, @searchTerm)) as w on w.[key]= LLPG.Id
left join 
    (select Rank * 10.0 as RankPostcode, [KEY] 
     from FREETEXTTABLE(LLPG, Postcode, @searchTerm)) as p on p.[key]= LLPG.Id
where
    LLPG.Language = @language and
    StatusCode = 1 and
    LPIStatusCode = 1 and
    Usage LIKE 'Res%' and
    Replace(Postcode, ' ', '') = Replace(@postcode, ' ', '') and
    (RankSAONDetails is not null or
     RankPAONDetails is not null or
     RankStreet is not null or
     RankWard is not null or
     RankPostcode is not null)
order by
    RankTotal desc
offset @offset rows
    fetch next @limit rows only
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
IeuanW
  • 228
  • 1
  • 9
  • 25
  • @Flater ye, the database was created using the code first approach. There is only one table so no FK or relationships matter. – IeuanW Jun 04 '21 at 14:55
  • @Flater how does that not answer your question? You asked if I've set up the FK/ relationships/ navigational properties using entity framework. My answer said there is only 1 table so nothing needed to be setup. – IeuanW Jun 04 '21 at 15:03

0 Answers0