I did raw SQL query below to select only certain fields from a table.
var qry = "SELECT ptitle, pname, paid, pidno, pdob, pgender, ptelh FROM patient where ";
if (strPatientName != "")
{
qry += "name like @name ";
if (strMRN != "")
qry += "&& id like @id ";
}
var query = db.Database.SqlQuery<patient>
((qry), new SqlParameter("@name", "%" + strPatientName + "%"), new SqlParameter("@id", "%" + strMRN + "%")).ToList();
But when i run, it gives out an error with the column that i didn't include in the query.
'System.Data.Entity.Core.EntityCommandExecutionException' occurred in EntityFramework.SqlServer.dll but was not handled in user code
Additional information: The data reader is incompatible with the specified 'project.Models.patient'. A member of the type, 'nbid', does not have a corresponding column in the data reader with the same name.