title: Optimize method for searching(ASP.NET Core)
body: <p>I have a method to get value from the database via criteria</p>
  
  <p>Here is this method</p>
  
  <pre><code>public async Task&lt;ListResultDto&lt;PropertyTenancyDto&gt;&gt; GetPropertySuggestions(string address,
          int? landlordId)
      {
          var tenantId = AbpSession.TenantId;
          if (tenantId == null)
          {
              throw new UserFriendlyException(L("FunctionalityIsNotAvailable"));
          }
  
  
          var query = _propertyRepository.GetAll()
              .Include(i =&gt; i.Addresses)
              .Include(x =&gt; x.Sites)
              .WhereIf(!address.IsNullOrWhiteSpace(),
                  p =&gt; (p.Addresses.FirstOrDefault().Line1
                            .StartsWith(address.Trim(), StringComparison.OrdinalIgnoreCase) &amp;&amp;
                        p.TenantId == tenantId &amp;&amp; p.Status == PropertyStatus.ReadyToLet) ||
                       (p.Addresses.FirstOrDefault().Line1
                            .StartsWith(address.Trim(), StringComparison.OrdinalIgnoreCase) &amp;&amp;
                        p.LandlordId == landlordId &amp;&amp; p.Status == PropertyStatus.ReadyToLet));
  
          var properties = await query.ProjectTo&lt;PropertyTenancyDto&gt;(ObjectMapper).OrderBy(x =&gt; x.Id).ToListAsync();
          return new ListResultDto&lt;PropertyTenancyDto&gt;(properties);
      }
  </code></pre>
  
  <p>It works well, but on huge amount of data (67K values) in database it works very slow (15-30 seconds)</p>
  
  <p>This method is searching for a property via address string</p>
  
  <p>I tried to optimize database query and create index to the <code>Line1</code> field. But it not helps.</p>
  
  <p>This I get in expression of query</p>
  
  <blockquote>
    <p>value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable<code>1[PM101.PMProperties.Property]).Include(i =&gt; i.Addresses).Include(x =&gt; x.Sites).Where(p =&gt; (((p.Addresses.FirstOrDefault().Line1.StartsWith(value(PM101.Tenancies.TenancyAppService+&lt;&gt;c__DisplayClass27_0).address.Trim(), OrdinalIgnoreCase) AndAlso (Convert(p.TenantId, Nullable</code>1) == value(PM101.Tenancies.TenancyAppService+&lt;>c__DisplayClass27_0).tenantId)) AndAlso (Convert(p.Status, Int32) == 3)) OrElse ((p.Addresses.FirstOrDefault().Line1.StartsWith(value(PM101.Tenancies.TenancyAppService+&lt;>c__DisplayClass27_0).address.Trim(), OrdinalIgnoreCase) AndAlso (p.LandlordId == value(PM101.Tenancies.TenancyAppService+&lt;>c__DisplayClass27_0).landlordId)) AndAlso (Convert(p.Status, Int32) == 3))))</p>
  </blockquote>
  
  <p>Any more advice ho I can speed up this query?</p>