5

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 LoadBalancedString.IsDbAlive to true in the constructor or if another connection is alive after the timeout expired. If ever all the servers managed in the DbLoadBalancer are ...


4

MySQLConnectionManager DbConnection GetDbConnection() and List<string> SplitMultiHostConnectionString() Whenever you also need the value for a given key of a Dictionary<TKey, TValue> you shouldn't use ContainsKey() together with the Item getter but you should use TryGetValue(). Internally these three methods are calling the FindEntry() ...


4

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 glorified wrapper of a repository doesn't add much value to the service. I would question whether a service should yield IQueryable. I find a service to be in ...


4

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 is with database/external service/network? Have you measured processing and communication time? Stopwatch Do you have some kind of monitoring of application, ...


3

Some quick remarks: Why isn't PaidDate a DateTime? What is a "Shopping"? (I realize that often naming things is hard, but be careful when inventing new English words that do not adequately describe their contents, because the next person to maintain this code will find it harder to do so when they have to first decipher various terms.) Use descriptive names:...


3

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 alternate solution to tackle exactly that. Precisely, it is easier to maintain and can be adapted to other models as well. In the whole code I only found a ...


3

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 remember who suggested it, I took the foreach loop and adapted to my case, for my point of view the foreach loop is the fasted way, and also I can turn it into a ...


2

You can improve the testability of your code by: Refactoring SplitMultiHostConnectionString() into it's own class Passing in the connection strings instead of accessing ConfigurationManager (thus removing the dependency on ConfigurationManager) This will make your class no longer static, but you can make it a singleton via the DI framework moving the logic ...


2

DRY Principle You should write DRY (don't repeat yourself) code. Each of your if-blocks contains the following pattern: using (ELECTROPEntities db = new ELECTROPEntities()) { try { var x = getData(db) .Where(predicate).ToList(); return PartialView("multi", x); } catch (Exception ex) { return Json(...


2

By default, Entity Framework will create the foreign key with the name of the entity primary key that is referenced by the navigation property. // Navigation Propertites // // (one-to-x) relation public User User { get; set; } // (many-to-x) relation public ICollection<User> Users { get; set; } // works vice versa For the ForeignKey ...


1

One main remark: the paging method is too busy. The number of arguments is a tell-tale. The parts that don't belong there are filtering and sorting. In general, a method returning any paged result, should only receive an IQueryable and the paging instructions page number and page size. Your second method is almost there. After removing the superfluous ...


1

Some quick remarks: There are almost 90 white-space characters before I can see the arguments to GetPaginatedSearchAsync. In such cases, move the parameters to the next line. Consider renaming PaginatedDataResult and ProductSearchResult (is the "Result" part of the name necessary?), and even GetPaginatedSearchAsync (is there a non-async method? ...


1

Couple of pointers. You are mixing data notation and fluent mapping. replace NotMapped attribute with .Ignore fluent mapping. Also I think its cleaner to move each entity into its own mapping config class using IEntityTypeConfiguration<T> Dont mix DTO and entities like that. Best practice is to project your entities to DTOs.


1

I seem to be able to create a new student, & to be able to add them to the BindingSource. I know this because the show up in the DataGridView. But, their id value is always 0. And, I need for the id value to be unique. When I save the changes made in the BindingSource to the underlying db file the new students are not saved. If I edit the credits of a ...


1

Here is an approach to get rid of some of the redundancy: First write an extension Method static IQueryable<Product> FilterForParameters (this IQueryable<Product> query, string price, string weight, string dimensions, string trend) { if (price != null) query = query.Where(p => p.Price.ToLower().Equals(price.ToLower())); ...


1

First off, the Include is ignored because you project the result to a new result (Select(x => new{ ... }). So you may as well remove it. Then, there is some room for improvement by eliminating the repetitive parts. It's much easier to do this in query syntax: var customers = from cst in _customerRepository.All() // Assuming this method exists let ...


1

It's hard to answer your question with a definitive answer as so much information is missing and a lot, depends also on the other UI screens data that you need to fill or that other may have opened. You’re going to get issues when performing aggregates on the same table that you provide row data on as you might end-up in a deadlock, even with yourself. I'm ...


1

EF knows about all navigation properties. So, instead of using reflection and try to figure it out by myself, I can just ask the DbContext about navigation properties. Here's a wonderful SO answer that does exactly that.


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