Implementing retry logic for deadlock exceptions

How about something like this: public T DeadlockRetryHelper<T>(Func<T> repositoryMethod, int maxRetries) { int retryCount = 0; while (retryCount < maxRetries) { try { return repositoryMethod(); } catch (SqlException e) // This example is for SQL Server, change the exception type/logic if you’re using another DBMS { if (e.Number == 1205) // SQL Server error code … Read more

Generate POCO classes in different project to the project with Entity Framework model

Actually the T4 templates in EF 4.0 were designed with this scenario in mind 🙂 There are 2 templates: One for the Entities themselves (i.e. ModelName.tt) One for the ObjectContext (i.e. ModelName.Context.tt) You should put the ModelName.tt file in you POCO project, and just change the template to point to the EDMX file in the … Read more

Implementation of Repository Pattern in Python?

Out of my head: I define two example domains, User and Animal, an base storage class Store and two specialized Storage classes UserStore and AnimalStore. Use of context manager closes db connection (for simplicity I use sqlite in this example): import sqlite3 def get_connection(): return sqlite3.connect(‘test.sqlite’) class StoreException(Exception): def __init__(self, message, *errors): Exception.__init__(self, message) self.errors … Read more

Multiple Git repositories for each Eclipse project or one Git repository

It depends on how closely-related these projects are. Ask yourself the following questions: Will they always need to be branched/tagged together? Will you want to commit over all projects, or does a commit mostly only touch one project? Does the build system operate on all of them or do they have a boundary there? If … Read more

What specific issue does the repository pattern solve?

I think the term “repository” is commonly thought of in the way the “repository pattern” is described by the book Patterns of Enterprise Application Architecture by Martin Fowler. A Repository mediates between the domain and data mapping layers, acting like an in-memory domain object collection. Client objects construct query specifications declaratively and submit them to … Read more

What exactly is the difference between a data mapper and a repository?

Suppose your application manages Person objects, with each instance having name, age and jobTitle properties. You would like to persist such objects, retrieve them from the persistence medium and maybe update (say, on their birthday, increment the age) or delete. These tasks are usually referred to as CRUD, from Create, Read, Update and Delete. It … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)