2011-07-14 149 views
1

我剛剛將數據訪問從Linq轉換爲SQL到Linq to Entities。我已經創建了我的edms,並且已經更新了我的類,如下所示,但是我收到了連接未找到的任何錯誤。 錯誤位於ModelDesigner.cs文件中。對此有何幫助?謝謝〜蘇珊〜LINQ to Entities:數據庫連接失敗

錯誤報告:

指定命名的連接或者未在 配置中找到,不打算與EntityClient提供者, 或無效使用。

Line 48:   /// Initializes a new FVTCEntities object using the connection string found in the 'FVTCEntities' section of the application configuration file. 
Line 49:   /// </summary> 
Line 50:   public FVTCEntities() : base("name=FVTCEntities", "FVTCEntities") 
Line 51:   { 
Line 52:    this.ContextOptions.LazyLoadingEnabled = true; 

這裏是我的代碼爲我的數據訪問層:

namespace DL 
{ 
    public class DLgetRestaurants 
    { 
     FVTCEntities db = new FVTCEntities(); 

     public List<RESTAURANT> getRestaurants(string cuisineName) 
     { 
      var cuisineID = db.CUISINEs.First(s => s.CUISINE_NAME == cuisineName).CUISINE_ID; 

      List<RESTAURANT> result = (from RESTAURANT in db.RESTAURANTs.Include("CITY").Include("CUISINE") 
             where RESTAURANT.CUISINE_ID == cuisineID 
             select RESTAURANT).ToList(); 


      return result; 
     } 
    } 
} 

回答

0

機會是你的連接字符串沒有指定的元數據資源。你能發佈你的連接字符串嗎?

http://msdn.microsoft.com/en-us/library/cc716756.aspx

+0

這裏是從App_Code文件文件的連接:節點 <添加名稱= 「FVTCEntities」 的connectionString =「元數據= RES://*/Model.csdl | RES:// * /型號.ssdl | res://*/Model.msl; provider = System.Data.SqlClient; provider connection string = " data source = SFP; attachdbfilename = H:\ ASP.Net \ FVRG \ FVRG \ App_Data \ FVTC.mdf;集成安全= TRUE; multipleactiveresultsets = TRUE;應用=的EntityFramework " 「的providerName =」 System.Data.EntityClient」 /> 節點 – Susan

+0

如果你把一個斷點,並使用ConfigurationManager.ConnectionStrings你確實看到在連接字符串中有? – Jeff

+0

對不起,我之前沒有使用Confg Mgr。我打開了BUILD。配置經理。我如何選擇ConnectionStrings?另外,應該在我的設計器文件中設置斷點嗎? – Susan