-2

How use SQL primitive in C# entities?

Example:

SELECT studentID, studentName 
FROM dbo.Student

I did:

using(studentEbestuur db = new studentEbestuur())
{
     var ListST = db.ChungLoais.SqlQuery("SELECT studentID, studentName FROM dbo.Student").ToList();
}

but I get an error:

error message

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • What is the rest of the "Additional information" ? Please paste the entire exception detail into your question, not an image. – Crowcoder Apr 28 '18 at 11:07
  • What exactly are you trying to achieve? It seems to me that you are looking for something like: `db.ChungLoais.Select(s => new { s.studentId, s.studentName });` – Federico Dipuma Apr 28 '18 at 11:15

1 Answers1

0

What's the point? You obviously have an Entity Framework model of this table - why not use the Entity Framework capabilities instead of resorting back to "raw" low-level SQL??

Use this instead:

using(studentEbestuur db = new studentEbestuur())
{
     var ListST = db.ChungLoais.Select(x => new { x.studentID, x.studentName }).ToList();
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459