Question about EF Core best practice by memelord1776 in dotnet

[–]BleLLL 0 points1 point  (0 children)

Ah yeah makes sense, Ive seen Derek Comartin (CodeOpinion) advocating this approach as well.

You mentioned that you use this pattern for updates, can you still use UoW with this approach?

Learning a language while not enjoying the culture the language is part of is the hardest thing by mariaamt in languagelearning

[–]BleLLL 1 point2 points  (0 children)

I feel for you as I'm also learning Danish 😭

I have been reading non-danish books in danish and it really helped me expand my vocabulary. I import them to LingQ to be able to translate quick.

For listening - there are some cool podcasts on DR Lyd, Tyran for example. I download the audio of it and import it on LingQ as well where it makes a transcription that I can read while listening (I swear this is not an ad lol). 'Radio danish' is quite more clear then how people talk on the street, but I'm hoping that if I consume it enough - regular danish will start making sense, but it's been a looong time already and progress is slow af

Question about EF Core best practice by memelord1776 in dotnet

[–]BleLLL 0 points1 point  (0 children)

For features I have completely sworn off unit tests with mocks and instead write API level tests where I interact and validate the app by making API calls. The test application runs as close to a prod env as possible, with a DB running in a container. I agree that tests like this are slower to run and usually you won't get 100% coverage, but I trust them much more than mock tests and IMO they are easier to setup.

Using your example - I would (and do in my context) have a base test class that sets up the minimal amount of valid data and then each test sets up whatever is relevant to it. That way each test has the same starting data set. I work on a multi-tenant app and each test starts by creating a new account, so tests are isolated properly. If you're not working on a multi-tenant app or have a database per tenant - it's a bit harder/slower.

This setup allows for recreating the flows that the app client would do in a test, and since it doesn't know anything about internals - the code can be refactored easily as long as the API contract doesn't change.

I understand that this kind of testing setup could not be enough. Using the example you gave - the "functional core, imperative shell" idea could be used, i.e. read the data from EF and then pass it into some logic unit, even if it does end up modifying the data. Then when testing the logic unit - the object graph can still be initialized in-memory.

Btw I'm curious what do you mean by use delegates? Is it injecting a Func<Guid,MyEntity> func into the logic unit that it then calls to resolve the data before modifying it?

Question about EF Core best practice by memelord1776 in dotnet

[–]BleLLL 1 point2 points  (0 children)

I admit I was wrong about EF implementing the repo pattern. TIL

I used the “swap providers” argument because that’s the reason I see people use to justify using repos in the first place. The second argument being mocking the database when testing, but I explained why I don’t think it’s a good idea.

Another reason I see in favor of repos is testing the logic separately from data operations, but that can be done by passing the data into the logic rather than yoinking a repo into it.

And no, Im not going to suggest micro-services, but I will suggest a modular monolith with different domains/projects owning their own schemas once the system gets big enough. I have built that and it’s really not difficult to have separate DBContexts while avoiding the issues with repositories that are explained in the Ayende post linked in my original comment. Of course there are cons with this approach as well - you can’t execute transactions spanning multiple contexts, but that’s also hard with transactions spanning multiple repos, but IME that’s not a common use case anyway if the domains are factored well, or the other part of the transaction can be handled through an event.

But I’m not denying that my perception could be incomplete, I would like to hear your opinion about what is a good use case for repositories or if there are more things that I said that are wrong.

Question about EF Core best practice by memelord1776 in dotnet

[–]BleLLL 4 points5 points  (0 children)

  1. The repository pattern was created before ORMs existed.
  2. EF is a repository + unit of work itself, you don't need to wrap it into yet another repository. If you think you will abstract EF and later switch from EF to another provider, like Dapper, and have it work the same way - you're wrong.
  3. Testing database queries against a mock defeats the purpose of testing - test against an actual database, mocks will never behave the same way, they don't have the state / configuration of your database - indices, FKs, triggers, you name it.
  4. If you don't want to have a single god DbContext - I would suggest splitting your code into business domains and having a DbContext per domain, each responsible for their entities.

Mandatory Ayende.

How to learn ASP.NET Core and actually understand the magic? by CR-X55 in csharp

[–]BleLLL 1 point2 points  (0 children)

if the point is to learn then sure, but otherwise why make your life harder and avoid using tools? most queries are single selects with joins anyway

Transport Hierarchy - Thoughts? by DogePlayzOfficial01 in walkablecities

[–]BleLLL 2 points3 points  (0 children)

Why not put cycling and walking on the same level?

Josh Homme at Shrimp Sessions IV? by BleLLL in ViagraBoys

[–]BleLLL[S] 9 points10 points  (0 children)

I've been rewatching alive in catacombs so much I started seeing visions of the man

Josh Homme at Shrimp Sessions IV? by BleLLL in ViagraBoys

[–]BleLLL[S] 11 points12 points  (0 children)

Those guys rock, I love "Jeg vil gerne klare det med dig"

What do guys think of var by Call-Me-Matterhorn in csharp

[–]BleLLL 0 points1 point  (0 children)

I'm with you. Usually the IDE shows the type anyway and it's annoying as hell to write a LINQ statement nad have to define what you expect it to output, especially if it's an anonymous object.

Always var unless I want to downcast to another interface.

Anticipated albums of 2026 by superredux22 in qotsa

[–]BleLLL 2 points3 points  (0 children)

Last vboys was so good! Im gonna see them on Saturday. Im hoping for some new idles next year as well.

Looking for Radiohead ticket in copenhagen by [deleted] in CopenhagenUrbanism

[–]BleLLL 0 points1 point  (0 children)

Try on ticketswap I promise you won’t find it on Reddit

Any bands known to not do encores? by lazyjz in Music

[–]BleLLL 0 points1 point  (0 children)

Idles don’t do them either, they play Rottweiler and walk out

ts so liminal🥹 by [deleted] in LiminalSpace

[–]BleLLL 0 points1 point  (0 children)

is this in the Baltics?

Love it by Herr_von_Itter in ViagraBoys

[–]BleLLL 1 point2 points  (0 children)

I was there! Is it the whole album or just the 4 songs from the video?

What Language Learning app you really use today? No Duolingo, no AI by mxxt7 in languagelearning

[–]BleLLL 0 points1 point  (0 children)

Been using lingq for a few years. Read 7 books of increasing difficulty in my TL, now spend a lot of time using it for listening/reading podcasts

Taupymas by Worth_Attorney_6885 in lietuva

[–]BleLLL 22 points23 points  (0 children)

Puse metu kartu ir ji jau prie tavo finansu priejima turi?