0
I am in error in instantiating the service. It is generic and I need it so, because I can use any entity in it. When I start the service in Hibernate, I need to pass the entity I will work to use the bank mapping. That is, when I install the service passing Tipodocumento or Document, it uses the mapping of the entity Tipodocumento or Document. I will only use methods and properties of the parent entity, I just need to use the daughter class to access the mapping of the right table that I will search. on normal screens, I overwrite the methods passing the entity I need, but on the search screen, I need to do everything on the same screen, because it is impossible to make a screen for each search
Cannot implicitly Convert type 'Servicocadastromestre' to 'Servicocadastro'
public class TipoDocumento : CadastroMestre
{
}
public class ServicoCadastroMestre<T> : ServicoCadastro<T> where T : CadastroMestre
{
}
public abstract class ViewCadastroMestre<T> : ViewCadastro<T> where T : CadastroMestre
{
public abstract ServicoCadastro<T> GetServico();
public abstract T GetEntidade();
}
public class ViewPesquisa : ViewCadastroMestre<CadastroMestre>
{
public override CadastroMestre GetEntidade()
{
return new TipoDocumento();
}
////o problema está aqui
public override ServicoCadastro<CadastroMestre> GetServico()
{
return new ServicoCadastroMestre<TipoDocumento>();
}
}
///////aqui funciona normalmente///////
public class ViewTipoDocumento : ViewCadastroMestre<TipoDocumento>
{
public override TipoDocumento GetEntidade()
{
return new TipoDocumento();
}
public override ServicoCadastro<TipoDocumento> GetServico()
{
return new ServicoCadastroMestre<TipoDocumento>();
}
}
and
return new ServicoCadastro<TipoDocumento>();
works ?– Rovann Linhalis
makes the same mistake. Servicocadastromestre inherits from Servicocadastro, which is abstract... but I have tested take of abstract and instantiation it, but from the same error...
– Eric Martins
maybe it was the case to use an interface.
– Rovann Linhalis
não visualizei...

o problema está em passar TipoDocumento em return new ServicoCadastroMestre<TipoDocumento>(); onde é esperado CadastroMestre em ServicoCadastro<CadastroMestre>

public override ServicoCadastro<CadastroMestre> GetServico()
 { Return new Service
– Eric Martins
I don’t think that’s possible. in generic interfaces you can even use the concepts of covariance and countervariance, but in types like this, you would have to have an explicit conversion and I believe you will have problems converting a more specific type into a less specific type.
– Rovann Linhalis
really couldn’t. as I came from Delhi, I think he is much more open to inheritances. because of that, I needed to do a lot of error treatment. no c#, no need to treat anything. thanks for the help
– Eric Martins