I am creating a Base Form where I am not using it of type "Generic" because of problem with forms inheritance in C # with it.
In this basic form, I had to create a virtual method with "Generic", because it will be overwritten in the child class.
Error 1 'Project.REP.Desktop.Format.Error.ObterRegisterParametersGridView (System.Linq.Expressions.Expression>)': no suitable method found to override C: \ Users \ Nicola Bogar \ documents \ visual studio 2013 \ Projects \ Project .ERP.Solution \ Project.ERP.Desktop \ Form.Contest.cs 39 38 Project.REP.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.");
}
}
Son Form
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>();
}
}
}
}