C
C#12mo 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
Angius12mo 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
DrunkreaperOP12mo ago
when I try to use explicit cast I get this error when trying to use the controller
No description
Drunkreaper
DrunkreaperOP12mo ago
and with "out" this appears
No description
Drunkreaper
DrunkreaperOP12mo ago
will have to look more into the switch expression tho
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
Drunkreaper
DrunkreaperOP12mo 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 User12mo ago
Message Not Public
Sign In & Join Server To View
Drunkreaper
DrunkreaperOP12mo ago
I don't quite understand
Drunkreaper
DrunkreaperOP12mo ago
where in here am I gona use T
No description
Drunkreaper
DrunkreaperOP12mo ago
? or should it be inserted in the RepositoryFactory?
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?