C#C
C#4y ago
9 replies
zuf

EF Core & Repository pattern

Our app was initially built using MongoDB and we implemented a repository layer over it. We then migrated to postgres & EF Core and basically kept the repository layer in the initial migration phase.

Now I understand its more of an anti-pattern & we are ready to move away from it, what is the "norm" alternative? Instead of having repositories build extension methods? Like this? (very basic example from a blog post)
public static class MyLinqExtension 
{
    public static IQueryable<int> MyOrder 
        (this IQueryable<int> queryable, bool ascending) 
    {
        return ascending
            ? queryable.OrderBy(num => num)
            : queryable.OrderByDescending(num => num); 
    }
}

Mostly referring to Patrick's post here https://discord.com/channels/143867839282020352/536023005164470303/550428647719174363 which started the discussion in our team.

Biggest concern is wanting to re use queries in other services etc.
Was this page helpful?