0

I Write A SQl Query In Entity Frame Work

var query1 = database.Database.SqlQuery<customer>("select name from customer where shomaremoshtare ='" + txt_shomaremoshtare.Text.Trim() + "'");

When I Run This Code I Give This Error enter image description here

ehsankhan
  • 13
  • 2
  • Possible duplicate of [does not have a corresponding column in the data reader with the same name](https://stackoverflow.com/questions/24732320/does-not-have-a-corresponding-column-in-the-data-reader-with-the-same-name) – Gert Arnold Jan 18 '18 at 19:43

1 Answers1

1

You are returning only the name of the entity in your select, try to return all the fields like this:

var query1 = database.Database.SqlQuery<customer>("select * from customer where shomaremoshtare ='" + txt_shomaremoshtare.Text.Trim() + "'");

The type expected is customer not just a name.