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 ...
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 ...
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 ...
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. ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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.
<...
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 ...
4
votes
Creating a round robin MySQL connection manager
MySQLConnectionManager
DbConnection GetDbConnection() and List<string> SplitMultiHostConnectionString()
Whenever you ...
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 :
...
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 ...
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 ...
3
votes
Accepted
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 ...
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/...
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 ...
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:
...
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 ...
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 ...
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 ...
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 ...
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 ...
2
votes
DbSet<T> IncludeAll method
Include uses when you want to include ICollection properties or not int, string, ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
entity-framework × 397c# × 393
linq × 71
asp.net-mvc × 40
asp.net × 36
repository × 35
.net × 34
design-patterns × 32
performance × 27
asp.net-mvc-4 × 26
asp.net-web-api × 17
sql-server × 14
database × 14
mvc × 13
asp.net-mvc-3 × 10
sql × 9
linq-to-sql × 9
beginner × 8
wpf × 8
dependency-injection × 8
lambda × 8
asp.net-mvc-5 × 7
object-oriented × 6
unit-testing × 6
generics × 6