✅ 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.
4 Replies
None
You wouldn't do that
You'd have one repository for classrooms, one for parents
so the only option is to repeat the exact same method logic with all the Entities?
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'tWas 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.