C
C#14mo ago
Drunkreaper

✅ How to make Get methods work with multiple data types

Currently making a beginner school database project with EF that just has to communicate with tables. What would be the best way to make these get methods work with multiple Models? Tried using generic types and object but I'm always getting conversion errors.
No description
No description
No description
No description
4 Replies
Angius
Angius14mo ago
None You wouldn't do that You'd have one repository for classrooms, one for parents
Drunkreaper
DrunkreaperOP14mo ago
so the only option is to repeat the exact same method logic with all the Entities?
Angius
Angius14mo ago
No, another option would be to use generics properly But then you would be repeating the code that EF already contains You would be, basically, creating a wrapper so that you can do _repository.Get<Thing>() instead of _context.Things.First() Unless the strict requirement is to implement a generic repository, don't
Accord
Accord14mo 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.
Want results from more Discord servers?
Add your server