c# EF 6 how to make this better ?

cristopheB 551 Reputation points
2023-03-28T06:55:15.0933333+00:00

Hello all,

I need to find a solution for to have better performance on a method.

As you can see in the picture i have a method who is call on a MVC Controller.

This method will be call too much in more or less one hour.

This method FindEvents, take a list of string as parameters and if you look the code i see 2 problems of it

    1. the select *
  1. the where clause query are build with for each statement

Here is it what i can do for to have better performance:

  1. -> select * can be replace by annymous type for to avoid to get the > 60 column of the table and just take the field we need
  2. -> for the foreach loop, I wonder if it's better to build a foreach for to have this resutl in ('AAA,' 'BBB', 'CCC' )
     Or
    
    To send the long string like this 'AAA, BBB,CCC' make a splt in sql function and execute the query
    

Also do you think it will be better to used with EF store procedure ?

Any comment, way to have better performance will be apprecied ..

thanks for all

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,401 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sedat SALMAN 13,165 Reputation points
    2023-03-28T07:00:52.56+00:00

    you may have few options to improve the performance

    • Use a SQL stored procedure instead of Entity Framework
    • Use a projection to select only the columns you need Instead of using select *
    • Use a parameterized query instead of building the where clause with a loop:
    • Cache the results of the query

0 additional answers

Sort by: Most helpful