Use stored procedures and create proper indexes on tables. If the data is too large, consider creating table partitioning.
If you use Entity Framework Core, the [Index] attribute allows developers to define indexes directly on the entity class.