Skip to main content
9 votes
Accepted

How to optimize for loop with nested foreach

Since you've specifically asked about speeding your code up, I'll answer that first. The main issue you have here is that you're doing a server call for every value in ...
Turksarama's user avatar
5 votes

Joining to in memory List

Gert Arnold gave a great answer but let me suggest one more soution to try. Yes, data which is got from another source (rather than DB) can be processed in 2 ways: Download as small data part from DB ...
Tony's user avatar
  • 151
5 votes

Generic repository and generic service

Review Your design uses a dedicated repository and service for each entity. This might look like a great idea at first, but you'll soon realise the drawbacks of this design. Having a service as a ...
dfhwze's user avatar
  • 14.2k
5 votes
Accepted

Repository to update flights

The repository does not need to take responsibility for the errors - remove them from here. The flight repository should add CRUD operations to Flight Dto and not return a result - remove the result. ...
Margus's user avatar
  • 934
5 votes
Accepted

Creating a round robin MySQL connection manager

Aliveness issue As it is, your code does not perform the task you expect it to, because the LoadBalancer never reinstates "dead" connection pools. Notice that you only ever set ...
Vogel612's user avatar
  • 25.5k
4 votes
Accepted

Injecting a DbContext with an async constructor dependency

If you don't mind me asking, any reason you want to register the DbContext directly? I know .NET Core seems to want you to do that, but I don't like IoC containers deciding when to leave open or close ...
Daniel Lorenz's user avatar
4 votes

Navigation properties with sql/dapper

Your entities have a dependency to a connection object that's somehow available to them. If this is one instance you may experience technical impediments when ...
Gert Arnold's user avatar
  • 2,060
4 votes
Accepted

Service Layer, using Entity Framework 6.2

How do you like it? I don't like it ;-) Because... This is a repository and should be named ItemRepository Unless you can prove (with proper profiler results) that ...
t3chb0t's user avatar
  • 44.7k
4 votes

Creating a simple unit of work with Entity Framework and no repository

I can be very short about this: Single responsibility: a controller shouldn't also have Unit of Work responsibilities. The context itself is the perfect Unit of Work. You don't always need ...
Gert Arnold's user avatar
  • 2,060
4 votes
Accepted

Adding data to database using ASP.net and SQL-server part 2

Coding/naming conventions: All the information about this can be found in folllowing article: Naming Guidelines. Straight from the documentation: To differentiate words in an identifier, capitalize ...
Abbas's user avatar
  • 5,623
4 votes
Accepted

Adding data to database using asp.net and sql-server

I would personally encapsulate your instantiation of MusicStoreDBEntities in a using statement so that the database connection is properly closed and disposed of. <...
Sean T's user avatar
  • 181
4 votes
Accepted

ASP.NET MVC 5, EF 6 filter performance

It might be boring to hear it again, but I have to ask :) Why do you think your application need performance optimisations? Is your bottle neck in these parts of code which you provided? Maybe problem ...
Karol Miszczyk's user avatar
4 votes

Creating a round robin MySQL connection manager

MySQLConnectionManager DbConnection GetDbConnection() and List<string> SplitMultiHostConnectionString() Whenever you ...
Heslacher's user avatar
  • 51k
4 votes

Efficiency of finding one database record using two ID's

When using EF, it would be better if you query the database then create a list of the results. in GetCalculationByProduct method, see this line : ...
iSR5's user avatar
  • 6,383
4 votes

Efficiency of finding one database record using two ID's

Disclaimer: my practical knowledge of EF is limited. But when you are using a database the first step is to run an execution plan against your queries. Make sure that they run fast enough and within ...
Kate's user avatar
  • 8,313
4 votes
Accepted

EF 6.0.0.0 include linked table delete with reordering of data

If I understood the relations between your entities correctly, the code can be greatly simplified by making a single query using Include. This method load all ...
Alexander Petrov's user avatar
3 votes
Accepted

GroupBy(params string[] fields)

Here are a few things I noticed: ...
t3chb0t's user avatar
  • 44.7k
3 votes

How to optimize a nested foreach loop which is creating same data object (with different values)

when ever you want to solve violations of the DRY principle you have to convert similar code into equal code. If you look at the two inner loops: make the most inner loop using new local variables to ...
Timothy Truckle's user avatar
3 votes
Accepted

Performance concerns for synchronous action methods

How large does a database have to be with how many calls to it before the async overhead is worth it? You will have benefits immediately. SQL Server is a multi-user database and even for small/simple/...
Adriano Repetti's user avatar
3 votes
Accepted

Code-First Notes Database

Foreign Key Your foreign key is typed to List. I recommend using a HashSet to prevent adding the same entities twice to you ...
Nick Udell's user avatar
  • 5,247
3 votes
Accepted

Entity Framework Lazy loading performance comparison

1) Not sure if it impacts performance, but your first code fragment has one redunant order by: ...
JanDotNet's user avatar
  • 8,608
3 votes

Collect reporting data for each possible combination of filter properties

So now basically rewriting the whole answer. As OP asks: Basically I'm looking for a way to [...] avoid making a lot of if statements and parameter combination manually This answer provides an ...
FeRaaC's user avatar
  • 153
3 votes

Collect reporting data for each possible combination of filter properties

SOLVED this is the way I ended up doing it, don't know if it's the best way, but it works I took this idea from an answer that was posted here but now it's not anymore, and Honestly I don't ...
Manuel Gonçalves's user avatar
3 votes

Calculate sum of an attribute across multiple repositories

Some quick remarks: Why isn't PaidDate a DateTime? What is a "Shopping"? (I realize that often naming things is hard, but be ...
BCdotWEB's user avatar
  • 11.4k
3 votes

Concurrent Requests Handling in ASP.NET Web API 2

Code does not follow the following best practices : Naming convention (properties should be PascalCased). Method should have a single responsibility. Multiple ...
iSR5's user avatar
  • 6,383
3 votes
Accepted

EF save method that has three conditions

Let's start with proper names. Parameters and local variables must have camelCase style, properties must have PascalCase. When ...
Alexander Petrov's user avatar
2 votes

DbSet<T> IncludeAll method

Include uses when you want to include ICollection properties or not int, string, ...
Islam Alshiki's user avatar
2 votes

Threadsafe DBContext in singleton

I'm thinking of a few solutions: one would be is not making this a singleton at all, but instantiate a logger each time I need one. I can think of added overhead as a disadvantage for this ...
Shadetheartist's user avatar
2 votes

Get a grouped list with relational data

I would recommend moving the database access stuff from your "View Controller" and into more of a data access controller (think DAL). Also, it's been a bit since I've used Entity Framework, but if ...
Bardicer's user avatar
  • 186
2 votes

Ordering data by boolean

When reading the code the following is most clear and fastest to understand: OrderBy(u => u.IsDefault ? 0 : 1) It sounds like: "order by: if ...
CoperNick's user avatar
  • 121

Only top scored, non community-wiki answers of a minimum length are eligible