C
C#2y ago
Ice_

❔ ASP.net MVC repositories

I have three classes, each with their own interface and repository. Let's call the classes Lamp, Sockets and the third class is a basic "joining" class called LampSockets where you just add LampId and SocketId to the table. It's not the best way to join two classes but that was our way of doing things during this assignment. My question is, what's the best way to optimize the code? Should I only use the repositories related to the actual class or is it okay to use more than one repository in a class? Because a part of the assignment is to create something in the joining table without IDs, using a ViewBag with SelectList (which is done). But listing everything with names instead of Ids (in index) is troublesome when I can't use several repositories. How would I accomplish that? (I've not been disallowed to use several repositories but I'm just trying to follow the assignment criterias 😅)
4 Replies
Anton
Anton2y ago
how do your repositories look?
Ice_
Ice_2y ago
Since they all use interfaces and sort of look a like: Lamp GetLampById(int id); IEnumerable<Lamp> GetAllLamps(); void CreateLamp(Lamp lamp); void UpdateLamp(Lamp lamp); void DeleteLamp(int id); Repository-wise.. Constructor takes in a dbcontext and then use that for whatever puposes. Then I have the above mentioned methods (some variances).
Anton
Anton2y ago
db context? ef core?
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.