C
C#11mo ago
Drunkreaper

✅ Is it possible to convert a generic interface to a generic interface?

I'm trying to prevent the creation of multiple giant switches in a controller by passing the instantiation of the interfaces to a factory. Person is the parent class(model) and all the other ones are sub-classes that have no problem to convert to the parent class in another factory. Is this error appearing because it is impossible to convert interfaces?
No description
11 Replies
Angius
Angius11mo ago
And here I thought generic repositories were useless complexity. Now we have whole-ass generic repository factories lmao In any case, see if adding an out modifier on the generic parameter helps As in, interface IPersonRepository<out T> That, or use an explicit cast like the error says (Also, you can reduce the code amount by a fair bit by using the hint VS shows you on switch. It'll convert the switch statement into switch expression)
Drunkreaper
DrunkreaperOP11mo ago
when I try to use explicit cast I get this error when trying to use the controller
No description
Drunkreaper
DrunkreaperOP11mo ago
and with "out" this appears
No description
Drunkreaper
DrunkreaperOP11mo ago
will have to look more into the switch expression tho
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
Drunkreaper
DrunkreaperOP11mo ago
I see I am using EF in DataContextEF but it's probably not optimal and I still have to add the FK since now the entities only have the PK connections. I will prob try with extension methods as you said, will have to learn more about them TY for the lengthy advice Ok there is an automatic way to connect the DB with the entities but I was not able to do it initially so just built the context class by hand
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
Drunkreaper
DrunkreaperOP11mo ago
I don't quite understand
Drunkreaper
DrunkreaperOP11mo ago
where in here am I gona use T
No description
Drunkreaper
DrunkreaperOP11mo ago
? or should it be inserted in the RepositoryFactory?
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server