0
I am creating a Base Form where I am not using it of type "Generic" due to problem with inheritance of forms in C# with the same.
In this base form, I had the need to create a virtual method with "Generic", as it will be overwritten in the daughter class.
By overriding the method in the child class and "Swap" Generic for the class I am implementing I come across the following compilation error.
Error 1 'Project.ERP.Desktop.FormularioEstado.Get registrardpopulargridview(System.Linq.Expressions.Expression>)': no suitable method found to override C:Users Nicola Bogar Documents visual studio 2013 Projects Projeto.ERP.Solution Projeto.ERP.Desktop Formularioestado.Cs 39 38 Projeto.ERP.Desktop
Parent Form
public partial class FormularioBase : Form
{
public virtual List<object> ObterRegistrosParaPopularGridView<TEntity>(Expression<Func<TEntity, bool>> where = null)
{
throw new NotImplementedException("Método ObterRegistrosParaPopularGridView da classe FormularioBase não implentada.");
}
}
Formulário Filho
public partial class FormularioEstado : FormularioBase
{
public override List<object> ObterRegistrosParaPopularGridView<Estado>(Expression<Func<Estado, bool>> where = null)
{
using (ProjetoContext contexto = new ProjetoContext())
{
if (where == null)
{
return contexto.Estados.Include(x => x.Pais)
.Select(x => new
{
Handle = x.Handle,
Descricao = x.Descricao,
Sigla = x.Sigla,
Pais = x.Pais,
PaisHandle = x.PaisHandle,
PaisDescricao = x.Pais.Descricao,
DataCadastro = x.DataCadastro,
DataAlteracao = x.DataAlteracao
}).ToList<object>();
}
else
{
return contexto.Estados
.Where(where)
.Select(x => new
{
Handle = x.Handle,
Descricao = x.Descricao,
Sigla = x.Sigla,
Pais = x.Pais,
PaisHandle = x.PaisHandle,
PaisDescricao = x.Pais.Descricao,
DataCadastro = x.DataCadastro,
DataAlteracao = x.DataAlteracao
}).ToList<object>();
}
}
}
}
Virgilio Novic, my return to the list has to be an Object, because I am using the entityframework and I am performing John in tables, that is, the return is not the same class that I am performing the Where, I believe that is not the problem, because I created the same way you sent less return as Generic, but I think C# has some contract that forces the override method to be the same as the one defined in the FATHER class.
– Nicola Bogar
I ended up editing the post because I forgot to put <Status> in the method I’m doing the right override. But still the problem persists. I did a test here and when I’m doing it the way you told me to do it, Get registrosparapopulargridview<Status>(Expression<Func<Status, bool>> Where = null) The <Status> that is well ahead of the method C# recognizes as Generic, So he doesn’t really find the class I’m trying to use, you know ? That’s the problem.. =/
– Nicola Bogar
Okay, Perai, I’ll edit the post.. Momentoo.
– Nicola Bogar
See if editing helps anything buddy.
– Nicola Bogar
I agree with you on this issue, but is that this select is only for popular grid, I only use the object to perform Where in the entity I am working on.
– Nicola Bogar