What I know about web development I can count on one hand. In an effort to change that I have begun to look at asp.net web pages as this technology seems to have a low technical barrier to entry and sits nicely, in my view, above plain ‘ol HTML.
I have been working through some samples and something has caught my eye. To create a connection and query a database you simply have to do this:
@{
var database = Database.Open("deanvmc");
var sqlQuery = "SELECT * FROM Articles";
var data = database.Query(sqlQuery);
}
From that I seem to be able to access the row data from the returned table in the following fashion:
@foreach(var row in data)
{
<article>
<h3>@row.Heading</h3>
<nav>
<ul>
<li>@row.DatePosted</li>
<li>@row.Category</li>
<li>0 Comments</li>
</ul>
</nav>
<p>@row.SubHeading</p>
</article>
}
Is this an ORM at work? Is it correct to assume that the object contained in row will always be mapped to the columns returned from the sqlQuery?
Also, is this a function of webmatrix as a stack or asp.net web pages as a library? I am a little confused about where one ends and the other begins.
The code above does not use an ORM – it is simply mapping fields returned from the database view to the row object returned by your query. So your assumption is correct – all of the object properties are mapped to the columns returned from the query.
WebMatrix itself is just a web development tool – it provides the editor, templates, and other dev tool type things. The libraries you’re using (ASP.NET Web Pages with Razor & C#) are the stack on top of which your application is built. WebMatrix happens to also support non .NET technologies such as PHP, and may support more in the future.
I know this was kind of open ended, but hopefully I was some help. Happy Coding!