2015-04-15 1 views
0

Bonjour, j'ai créé un site Web vide C#. J'ai créé une base de données et je suis en train de lire le contenu d'un .cshtmlVisual Studio 2013 WebSite Project Database.Open

@{ 
    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> 

au début, je suis une erreur

Erreur 1 Le nom de « base de données » n'existe pas dans le contexte actuel

qui a été fixé après que je l'ai fait https://www.nuget.org/packages/WebMatrix.WebData/

maintenant j'obtiens une erreur de message

erreur 1 La méthode d'initialisation de démarrage préalable à la demande de démarrage du type WebMatrix.WebData.PreApplicationStartCode a généré une exception avec le message d'erreur suivant: Tentative par la méthode de sécurité transparent 'WebMatrix.WebData.PreApplicationStartCode.Start() pour accéder à la sécurité méthode critique 'System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport (System.String)' a échoué ..

+0

double possible ([tentative de méthode transparente de sécurité 'WebMatrix.WebData.PreApplicationStartCode.Start()'] http://stackoverflow.com/questions/17926552/attempt-by- sécurité-transparent-méthode-webmatrix-webdata-preapplicationstartcod) – Paddy

Répondre

0

Sonne comme ceci: Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.Start()'

« Pour moi, cette erreur était parce que je n'ai pas Microsoft .AspNet.WebHelpers installé après la mise à jour de MVC 4 vers MVC 5. Il a été corrigé en installant le paquet NuGet »

Install-Package -Id Microsoft.AspNet.WebHelpers 
+0

je l'ai fait et maintenant je reçois l'erreur de message suivant –

+0

Erreur La méthode d'initialisation de démarrage de pré-application Démarrer sur le type WebMatrix.WebData.PreApplicationStartCode a levé une exception avec l'erreur suivante message: Impossible de charger le fichier ou l'assemblage 'WebMatrix.Data, Version = 3.0.0.0, Culture = neutre, PublicKeyToken = 31bf3856ad364e35' ou l'une de ses dépendances. La définition de manifeste de l'assembly localisé ne correspond pas à la référence d'assembly. (Exception de HRESULT: 0x80131040). –

+0

try: Install-Package Microsoft.AspNet.WebPages.Data –