Thanacio
Thanacio
CC#
Created by Thanacio on 4/9/2025 in #help
Dapper - Unit of work between 2 repositories
I need to keep a common transaction between 2 repositories, but I'm not sure who will be responsible for rolling it back in case of failure. Those 2 repositories do share connection and transaction via parent, but one of them has to commit the transaction. How do people usually go about this? - Do I make it so that the service is responsible for coordinating the repositories? I'm too new but this sounds wrong because a transaction commit/rollback is the responsibility of the database layer. - Do I call one repository method through another? This would mean injecting a repository, and I read that it's bad practice. Sorry, I'm new to Dapper and Unit of Work as a pattern.
27 replies
CC#
Created by Thanacio on 4/4/2025 in #help
ASP.NET MVC - need opinion for viewmodel properties
I'm new to ASP.NET MVC, and I'm trying to make a simple project with N-tier architecture. I'm conflicted with how to represent a Country on my ViewModel. To put it simply, I want my domain model to only hold the CountryId, but I want the ViewModel to display the CountryName that corresponds to that CountryId. Right now I use this
public required string Country { get; set; }
public required int CountryId { get; set; } // foreign key for the Country table
public required string Country { get; set; }
public required int CountryId { get; set; } // foreign key for the Country table
I'm hiding the CountryId field on the page, but I want to keep it around so that I have fast country reads while editing an entry. I was wondering if creating a separate Country class to model countries (with id, name) is a good idea, but I don't plan on adding CRUD functionality on the countries themselves. And I also plan to keep the domain model storing just the countryId. Is there a common practice for this scenario?
57 replies