0

Hello i have created an empty Website C#. I created a database and i am trying to read the contents from a .cshtml

    @{
    var db = WebMatrix.Data.Database.Open("Test");
    var selectQueryString = "SELECT * FROM Product ORDER BY Name";
}
<html>
<body>
    <h1>Small Bakery Products</h1>
    <table>
        <tr>
            <th>Id</th>
            <th>Product</th>
            <th>Description</th>
            <th>Price</th>
        </tr>
        @foreach (var row in db.Query(selectQueryString))
        {
            <tr>
                <td>@row.Id</td>
                <td>@row.Name</td>
                <td>@row.Description</td>
                <td align="right">@row.Price</td>
            </tr>
        }
    </table>
</body>
</html>

at first i got an error

Error 1 The name 'Database' does not exist in the current context

which was fixed after i did this https://www.nuget.org/packages/WebMatrix.WebData/

now i get a message error

Error 1 The pre-application start initialization method Start on type WebMatrix.WebData.PreApplicationStartCode threw an exception with the following error message: Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.Start()' to access security critical method 'System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(System.String)' failed..

  • possible duplicate of [Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.Start()'](http://stackoverflow.com/questions/17926552/attempt-by-security-transparent-method-webmatrix-webdata-preapplicationstartcod) – Paddy Apr 15 '15 at 14:24

1 Answers1

0

Sounds like this: Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.Start()'

"For me this error was because I did NOT have Microsoft.AspNet.WebHelpers installed after updating from MVC 4 to MVC 5. It was fixed by installing the NuGet package"

Install-Package -Id  Microsoft.AspNet.WebHelpers
Community
  • 1
  • 1
lloyd christmas
  • 556
  • 1
  • 4
  • 16
  • Error 1 The pre-application start initialization method Start on type WebMatrix.WebData.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'WebMatrix.Data, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040). –  Apr 15 '15 at 14:27
  • try: Install-Package Microsoft.AspNet.WebPages.Data – lloyd christmas Apr 15 '15 at 14:32