2013-06-06 58 views
1

我有兩個項目的解決方案:一個webApplication和一個具有edmx和所有實體框架邏輯的ClassLibrary。這工作很好,但如果我嘗試使用強類型數據,它開始出現問題。無法加載類型'EDMNearClass.ProductRepository.DesTagliaP'

在後面的代碼我用這個函數:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.ModelBinding; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using EDMNearClass; 

namespace WebSite 
{ 
    public partial class dettaglio_prodotto : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      //Response.Write(Page.RouteData.Values["DESCRIZIONE"]); 
     } 

     public IQueryable<ProductRepository.DesTagliaP> GetProduct_Taglie([RouteData("Id")] string itemId) 
     { 
      decimal ProdId = decimal.TryParse(itemId, out ProdId) ? ProdId : 0; 
      ProductRepository pr = new ProductRepository(); 
      var myEnts = pr.taglieProdottiDesGetbyUId(1,ProdId).AsQueryable(); 
      return myEnts; 
     } 
    } 
} 

在ASPX部分,我用這個代碼:

<asp:Repeater ID="rpTaglie" runat="server" ItemType="EDMNearClass.ProductRepository.DesTagliaP" SelectMethod="GetProduct_Taglie"> 
    <ItemTemplate> 
     <div class="quanitybox"> 
      <label for="qty"><%# Item.Codice %></label> 
      <asp:TextBox runat="server" ID="quantita" CssClass="input-text qty" /> 
     </div> 
    </ItemTemplate> 
</asp:Repeater> 

智能感知工作,幫助我的choise的EDMNearClass.ProductRepository.DesTagliaP proprerty,但在運行時我收到錯誤。 如果我使用Eavl("Codice")和我刪除ItemType="EDMNearClass.ProductRepository.DesTagliaP",一切正常。

我檢查/ bin文件夾和EDMNearClass.dll EDMNearClass.pdb存在和更新。

我該如何解決這個問題?

回答

0

只是一個猜測 - 但我可以想象轉發器綁定不喜歡IQueryable。我會綁定到IEnumerable或只是一個List。會像下面的工作 - 不只是給你一個想法。

public List<ProductRepository.DesTagliaP> GetProduct_Taglie([RouteData("Id")] string itemId) 
     { 
      decimal ProdId = decimal.TryParse(itemId, out ProdId) ? ProdId : 0; 
      ProductRepository pr = new ProductRepository(); 
      var myEnts = pr.taglieProdottiDesGetbyUId(1,ProdId).ToList(); 
      return myEnts; 
     } 

編輯

我也想嘗試中繼明確地綁定到集合,而不是使用select方法屬性。看到這個答案

Using ItemType for strongly typed repeater control?

+0

感謝答覆,但我tryed與ListView中相同的解決方案,是一樣的。 我也試過你的解決方案,但不工作。 –

+0

請參閱編輯另一個想法。問候 –

+0

用這種方法我解決了問題,現在我不明白爲什麼,如果我使用例如'EDMNearClass.ufnGetProdottiDittaLingua_Result'(在TableValueFunction中鍵入autogenerate在edmx中),它在ListView中工作。 –

相關問題