I'm using entity framework and I have this class
public partial class TipoRequisicaoSubCategoria
{
public TipoRequisicaoSubCategoria()
{
this.Formularios = new HashSet<Formulario>();
}
public int Id { get; set; }
public int IdTipoRequisicao { get; set; }
public int IdSubcategoria { get; set; }
public virtual ICollection<Formulario> Formularios { get; set; }
public virtual subcategoria Subcategoria { get; set; }
public virtual TipoRequisicao TipoRequisicao { get; set; }
}
The table is
Table: tipo_requisicao_subcategoria
Columns:
ID_TIPO_REQUISICAO_SUBCATEGORIA int(11) AI PK
ID_TIPO_REQUISICAO int(11)
ID_SUBCATEGORIA
If I do a search using linq, the results are perfect, but when I tryng to do a search using SqlQuery method, I get the message:""The data reader is incompatible with the specified 'medicEntities.TipoRequisicaoSubCategoria'. A member of the type, 'Id', does not have a corresponding column in the data reader with the same name."
Here is the query that I'm using:
return _context.tipo_requisicao_subcategoria.SqlQuery(string.Format(@"SELECT TS.* FROM tipo_requisicao_subcategoria TS INNER JOIN
tipo_requisicao T ON T.ID_TIPO_REQUISICAO = TS.ID_TIPO_REQUISICAO
WHERE T.ID_ESPECIALIDADE = {0}", idEspecialidade)).ToList();
Ps: I'm using database first