C
C#9h ago
Faker

What is Repository pattern design and how to implement it

Hello guys, I was just learning about how to implement database connection using the EF Core, then I came across something known as Repository pattern. I read a bit about it; what I understood it's just a design pattern to write clearer and more maintanable code. It separates business logic and data access logic. This is where I'm a bit confused; what do we mean it "separates business logic and data access logic" please. I understood that we uses some kind of abstraction to separate these logic. Like we create a specific class for data access logic, we only want to interact with the database while, for the business logic, this is still a bit confusing; can someone elaborate please. When we picture the business logic and data access logic, how do we implement that in code please (Are there steps to follow?). Last thing, is this important? :c ..Can't I just merge everything, both logics?
12 Replies
Keswiik
Keswiik8h ago
repositories with EF is generally considered an anti-pattern as your db context is your repository as for the "business logic and data access logic", it's pretty straightforward the business logic side is what you're doing with the data (and constraints applied to it) data access is how you're storing and retrieving the data a repository isolates all of your interactions with a database from the code you have that uses said data
Faker
FakerOP8h ago
hmm what is an anti-pattern please; it's just something that add more complexity to our code?
Keswiik
Keswiik8h ago
stuff that is generally considered a bad idea or in poor practice
jcotton42
jcotton427h ago
Counterproductive practices. In the case of repos over EF, you are laying a repo over an existing one (the DbSets in the context). And a much less powerful one to boot.
Unknown User
Unknown User6h ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User6h ago
Message Not Public
Sign In & Join Server To View
Faker
FakerOP6h ago
yeah I see so, I don't have to use a repository thing with EF core, I can just skip it ?
Unknown User
Unknown User6h ago
Message Not Public
Sign In & Join Server To View
Faker
FakerOP6h ago
yep I see, creating another repository would be like the picture, trying to drive a car over a car ?
this_is_pain
this_is_pain5h ago
it's that by doing so you would create methods that dbset<> already has
Faker
FakerOP4h ago
noted, thanks !

Did you find this page helpful?