Trying to tackle a simple web application, I've created a project in Visual Studio 2017 that works fine when I'm using models that correspond with tables (I followed the tutorial at: https://msdn.microsoft.com/en-us/library/jj206878(v=vs.113).aspx ).
I'd like to just run a raw sql query so I can work with the results, manipulate and write back into another table, or just display the results
In my controller I have:
public ActionResult RunQuery001()
{
string query = "SELECT @@VERSION";
return View(db.Servers.SqlQuery(query).ToArray());
}
And I created a view that looks like:
@model IEnumerable<omfgshootmenow.Server>
@{
ViewBag.Title = "RunQuery001";
}
@foreach (var item in Model)
{
@Html.DisplayFor(model => item.ToString());
}
The code builds but when I execute I get an exception:
Message=The data reader is incompatible with the specified (model here) A member of the type, 'id', does not have a corresponding column in the data reader with the same name.
I keep thinking that the view is completely wrong (or the whole thing is) since the exception is referencing the key column of the model.
any help is appreciated.