locked
Differences between queries with full-text indexes RRS feed

  • Question

  • User399031849 posted

    I tried this query directly from SQL Management Studio and it finds me some records

    select *
    from Table
    WHERE CONTAINS (BUSINESSNAME, '"Business Name"')
    AND FREETEXT((ADDRESS,POSTAL_CODE,LOCALITY,PROVINCE, NATION),'string')

    But on the project using the Entity Framework function instead it does not find anything ... I would not want the problem to be the double quote that encloses the string

    this.context.Table.Where(x => (EF.Functions.Contains(x.BusinessName, $"\"{businessName}\"") &&
                                                               (EF.Functions.FreeText(x.Address, address) ||
                                                               EF.Functions.FreeText(x.Locality, address) ||
                                                               EF.Functions.FreeText(x.PostalCode, address) ||
                                                               EF.Functions.FreeText(x.Province, address) ||
                                                               EF.Functions.FreeText(x.Nation, address)) &&
                                                               EF.Functions.Contains(x.VATNumber, vatNumber));

    Wednesday, January 20, 2021 12:44 PM

All replies

  • User1312693872 posted

    Hi,marduk87RP

    Can you show us what the error is?

    Entity Framework does not natively support FullText searches.

    you can try LINQ Contains as a work-round, like:

    this._context.Table.Where(t => $"\"{businessName}\"".Contains(t.BusinessName)).ToList();

    The Tolist() is used to create a list to put the data searched from database.

    Best Regards,

    Jerry Cai

    Thursday, January 21, 2021 8:19 AM
  • User399031849 posted

    Thanks, I use ToList () in the calling function, my mistake was that in my function I also have other filters that I had not reported on SQL Management and in fact with the correctly filtered values I find a match

    Thursday, January 21, 2021 1:32 PM