2016-12-20 82 views
0

就打電話給我的WCF來填充我的DataGridView實體框架找不到我的連接字符串

private void button1_Click(object sender, EventArgs e) 
{ 
    ServiceReferenceReservations.ReservationsServiceClient srr = 
       new ServiceReferenceReservations.ReservationsServiceClient(); 
         gridData.DataSource = srr.getAllReservations(); 
} 

,這是什麼mycf並轉化businesslayer的返回類型有正確的

public List<clsReservation> getAllReservations() 
{ 
    List<clsReservation> oDataList = new List<clsReservation>().ToList(); 

    List<Reservation> mesReservations = BusinessLayer.Reservations.LoadAllReservationsEF(); 

    foreach (var item in mesReservations) 
    { 
     clsReservation cls = new clsReservation() 
       { 
        id = item.id, 
        lecteurID = item.lecteurID, 
        livreID=item.livreID 
       }; 
     oDataList.Add(cls); 
    } 

    return oDataList; 
}  

並且業務層將打電話給數據訪問層並返回數據

return DataAccessLayer.Reservations.LoadAllReservationEF(); 

然後我的數據訪問層使用實體框架

public static List<Reservation> LoadAllReservationEF() 
{ 
    List<Reservation> malisteReservation = new List<Reservation>(); 

    using (bibliothequeEntities dbcontext = new bibliothequeEntities()) 
    { 
     List<Reservation_SelectAll_Result> maliste = dbcontext.Reservation_SelectAll().ToList(); 

     var x = from p in maliste 
       select new Reservation 
         { 
          id = p.id, 
          lecteurID = p.lecteurID, 
          livreID = p.livreID, 
         }; 

     foreach (var item in x) 
     { 
      malisteReservation.Add(item); 
     } 
    } 

    return malisteReservation; 
} 

我的數據訪問層被扔在Model1.Context.cs錯誤:

沒有名爲「bibliothequeEntities」連接字符串可以在找到在DAL的應用程序配置文件

<connectionStrings> 
    <add name="bibliothequeEntities" 
     connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=arpa;initial catalog=bibliotheque;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" /> 
</connectionStrings> 

但我有在ConnectionString中我DAL,並在啓動項目調用WC F。我已經嘗試對「onModelCreating」方法發表評論以避免拋出錯誤,但仍然找不到解決方案

我在想什麼?

+0

請出示構造函數(只是宣言和任何'base'調用)爲'bibliothequeEntities' – sellotape

+0

公共bibliothequeEntities() :基部( 「名稱= bibliothequeEntities」) { } 保護覆蓋無效OnModelCreating(DbModelBuilder模型構建器) { //拋出新UnintentionalCodeFirstException(); } – bob

+0

是否.config文件指的是_main應用程序的配置文件,而不是「bibliothequeEntities」所在的程序集,如果它不同? – sellotape

回答

0

如果在IIS中託管,則需要將app.config文件的內容複製到您在IIS中託管它的虛擬目錄的web.config文件中。我不相信這是爲你自動完成的。

如果您使用其他東西來託管,您同樣需要找到主機正在執行的文件夾,並將內容複製到,其中 app/web.config。

總之,連接字符串需要位於主機的.config中,而不是任何其他程序集。

查看here瞭解更多詳情。

+0

它只是自己託管,我didn'i配置IIs或其他任何東西它只是一個wcf作爲客戶端winforms – bob

+0

公共虛擬ObjectResult Reservation_SelectAll () { return((IObjectContextAdapter)this).ObjectContext.ExecuteFunction (「Reservation_SelectAll」); } – bob

+0

這是拋出它由entitframework生成的錯誤的方法 – bob

0

連接字符串應該是WCF這一切都沒有必要,甚至把它放在dataccesslayer

相關問題