Does using the repository pattern with Entity Framework make sense?

I really enjoyed the Entity Framework Community Standup Ask Me Anything with Julie Lerman the other night (10th March 2021)… and of course a question about using the repository pattern with Entity Framework came up.

Should we use the repository pattern with EF?

I 100% agree with Julie when she said the two answers she doesn’t like are that we should…

1 – NEVER use the repository pattern with EF
2 – ALWAYS use the repository pattern with EF

so… with that out of the way check out the video to see in what situations the panel do believe using the pattern with EF make sense.

Personally I don’t use it by default¬†(I would use it occasionally) as I find in a lot of cases I don’t need the abstraction layer it provides and therefore would prefer to keep the solution as simple as possible and not over architect.¬†There are definitely uses cases for it though.

The purpose of the pattern is to provide an abstraction over your data layer so if you do use it don’t return IQueryable as IMHO it just defeats the whole purpose.. as now you’ve leaked or broken the abstraction.

One thought on “Does using the repository pattern with Entity Framework make sense?”

Leave a Reply

Your email address will not be published. Required fields are marked *