score:2
Due to you having lots of rows in your Document table, you are doing a non-sargable scan of the whole table! which is not ideal. Ideally you want to make it sargable so remove the leading or trailing % signs.
e.g. if you remove the leading % then it will be able to use an index on the FirstName column (as long as you create one). It can then seek to matches and just read that data and not the whole table.
You can try something like this in your linq code
YourDocuments.Where(x => EF.Functions.Like(x.FileName, $"{yourSearchString}%"))
If you want more control consider a stored procedure, but if this does the job then all good :)
If you just created an index on the FileName and kept the %...% syntax, It may use the index as mentioned by others above, it would still be a full scan of that index. The index will be smaller than the clustered index table, hence why SQL Server would use it, because it will do less logical page reads.
Source: stackoverflow.com
Related Articles
- Query Timeout in EF Core but runs fast in SSMS
- Optimize LINQ query that runs fast in Sql server?
- What would be a reasonably fast way to code this sql query in c#?
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- How to make filtration query fast in my C# code with MySQL?
- Could not find an implementation of the query pattern for source type 'System.Data.Entity.DbSet'
- NHibernate query runs only once, then throws InvalidCastException
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- ThenInclude not recognized in EF Core query
- The LINQ expression could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation EF Core 3.1
- Trouble with Entity Framework Linq Query: runs instantly in SSMS and 8-10s in EF LINQ
- Compare DateTime in EF Core Linq Query
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- Linq Stored Procedure Timeout but SSMS Quick
- LINQ Source Code Available
- Linq query runs in a fraction of a second, but .ToList() takes 3.5 seconds
- Entity Framework Core LINQ query with multiple where clauses
- Joining tables in EF Core Linq Query
- Linq fast intersect query - enhancement?
- Entity Framework Core linq query returns InvalidCastException
- EF Core using Let in query throw "Argument types do not match" exception
- prevent unnecessary cross joins in count query of generated sql code
- How to convert string to DateTime in C# EF Core query
- How to construct a raw SQL Query in EF Core with dynamic number of parameters
- .NET 4 Code Contracts: "requires unproven: source != null"
- EF Code First comparing null values generates strange query
- Which is fast : Query Syntax vs. Loops
- linq - how do you do a query for items in one query source that are not in another one?
- How can I write the following code more elegantly using LINQ query syntax?
- How to dynamic add filters to a LINQ query against an Odata Source in C#
- LINQ & Enums as IQueryable
- EFCore 3: How to compare string columns on server side
- How to show multiple fields in combobox using linq in C# Windows form?
- linq list of list sum of number
- filtering XML nodes containing a greater-than character in node text
- Overriding generic IEnumerable interface in child class
- Linq to NHibernate: 'System.Linq.EnumerableQuery`1[Entity]' cannot be converted
- Retrieving data from SQL server in batches
- SQL to Linq Equivalent
- Ordering a list by size using Linq
- Dynamic Linq - String.Split
- How can I create a DateTime value in a Linq Query?
- How to perform a group join in .NET Core 3.0 Entity Framework?
- How to Update previous row column based on the current row column data using LinQ
- joining statement with linqdatasource
- Resolving bool from linq query
- Linq select distinct values with comparison
- LINQ expression inside foreach loop
- LINQ Query for outerjoining Parent and child (nested) tables
- Not able to use IN query in LINQ with Entity Framework