2016-12-29 15 views
0

としてMDFファイルを添付できません私は、プロジェクトエクスプローラ/ App_Dataフォルダが空であることを確認します。私は削除していません。これは新鮮なプロジェクトです。は、私はASP.NET MVCプロジェクトを作成するために、VS 2015を使用して、次のエラーを発見していたデータベース

マイモデル:

namespace NailShop.Models 
{ 
    [Table("TechnicianDetails")] 
    public class TechnicianDetails 
    { 
     // model fields: 
     [Key] 
     public int TechnicianID { get; set; } // no semicolon 
     public int commentID { get; set; } 
     public int serviceID { get; set; } 
     public string firstName { get; set; } 
     public string lastName { get; set; } 
     public string introduction { get; set; } 
     public int rating { get; set; } 
    } 
} 

マイコントローラ:

public class TechnicianDetailsController : Controller 
{ 
    // GET: TechnicianDetails 
    public ActionResult TechnicianDetails(int id) 
    { 
     // Model class: 
     TechnicianDetails technicianDetails = new Models.TechnicianDetails(); 
     // DBContext class: 
     TechnicianContext technicianContext = new TechnicianContext(); 

     // map the row in database table to model : assign the TechnicianID in the db to the parameter technicianID of the action method 
     technicianDetails = technicianContext.Technician.Single(x => x.TechnicianID == id); 


     return View("~/Views/Technician/TechnicianDetails.cshtml", technicianDetails); 
    } 
} 

私の接続文字列:私は、サーバーエクスプローラで接続文字列を割り当てる - > [接続の追加] - > [サーバーとデータベースを選択 - >詳細 - >データソースをコピーして貼り付けます。データベースは Visual Studioのサーバーエクスプローラ

経由でも接続可能である

enter image description here

パッケージマネージャコンソール:

は私が Cannot attach the file *.mdf as databaseからのステップに続き、「SQL Server Management Studioをして、それを修正するために、」ガイドを選択してください。

私はまた、からの手順に従っ:Cannot attach the file .mdf as database

私は

SQLLocalDB info 

を実行して、2つのインスタンスが見つかりました:私は、その後、停止、削除、各インスタンスを起動し、その後

MSSQLLocalDB 
ProjectsV12 

を。

私もupdate-databaseを実行し、次のエラーを取得:

enter image description here

答えて

0

私は、接続文字列(TechnicianDetailContext)の名​​前は、私が作成したクラスinheritting DBContextクラスと一致していませんがわかりました(TechnicianContext)。

したがって、Visual Studioは、ショーなど、さまざまなローカルサーバへのポイントでは、画像を添付することを、defaul接続でTechnicianContextを実行します:

enter image description here

関連する問題