Skip to main content

DON'T PUT a repository layer

It's not necessarily that you should not write a repository in C#, but rather that it's important to carefully consider whether a repository is necessary for your specific use case. In some cases, a repository can add unnecessary complexity and make your code harder to understand and maintain.

One reason to be cautious about using a repository is that it can lead to over-abstraction. By creating a separate layer of abstraction for your data access logic, you can make your code more difficult to understand and modify. This is especially true if you are using an ORM like Entity Framework, which already provides a lot of abstraction for working with databases.

In addition, writing a repository can be time-consuming and may not provide significant benefits over using an ORM directly. Many ORMs like Entity Framework already provide a lot of the functionality that you would typically implement in a repository, such as CRUD operations and querying.

That said, there are cases where a repository can be useful, such as when you need to work with multiple data sources or when you need to provide a uniform interface for data access across different parts of your application. In general, however, it's important to carefully consider whether a repository is necessary for your specific use case and to avoid over-complicating your code unnecessarily.