2011-02-15 183 views
1

我在ASP.NET網站中使用LinqToSql類,假設我有一個名爲Testimonials的實體。兩頁使用這種類型 - 第一個是所有現有的Testimonial記錄的列表,第二個是用於管理記錄的添加/編輯器。方法'X'不是屬性訪問器(Linq/LinqToSql)

在我們用一個簡單的查詢的第一頁,例如:

Public Function GetTestimonials() As IQueryable(Of Testimonial) 
    Return From testimonial In Context.Testimonials Select testimonial 
End Function 

這使得人口DataGrid與歸還物品,但添加/編輯頁面上我們曾經更改查詢,以便稍微:

Public Function FindTestimonial(ByVal id As Integer) As Testimonial 
    Return (From testimonial In Context.Testimonials Where testimonial.ID = id 
      Select testimonial).FirstOrDefault() 
End Function 

這個查詢死之前,甚至還試圖填充任何東西,並顯示以下消息:

The method 'Testimonial.add_PropertyChanged' is not a property accessor 

我有幾乎相同的方法,其他數據對象已經和仍然執行得很好。我能想到的一個直接區別是,該表最近已在數據庫中更新,從dbml設計器中刪除,並重新添加到dbml設計器中。一段時間以來,其他表格都沒有經歷過這個過程。

爲什麼會發生此異常,如何正確配置我的項目以糾正問題?

我要看看自己現在(明顯),但最初的谷歌搜索沒有出現任何可能阻止我抽穗這裏,並說實話我沒有時間去全力以赴瞭解並理解爲什麼 - 當我找到答案時就必須來!

編輯:

使得調用FindTestimonial的代碼如下(我不能看到該鏈接被加布建議的薰鯡魚,但是,我不是一個在這種困境的答案):

Private Sub PopulateView() 
    If (TestimonialId > 0) Then 
     Dim testimonialService = DataServices.GetService(Of TestimonialService)() 
     Dim testimonial = testimonialService.FindTestimonial(TestimonialId) 
     If (testimonial IsNot Nothing) Then 
      NameTextBox.Text = testimonial.Name 
      LocationTextBox.Text = testimonial.Location 
      MessageTextBox.Text = testimonial.Message 
      PublishDateTextBox.Text = testimonial.PublishDate 
      IsActiveCheckBox.Checked = testimonial.IsActive 
     End If 
    End If 
End Sub 

Public ReadOnly Property TestimonialId() As Integer 
    Get 
     Return Domain.Web.UI.QueryString.GetValue(Web.UI.QueryStringParameter.TestimonialId) 
    End Get 
End Property 

哪裏DataServices僅僅是它們與一個頁面(例如代碼完美的作品遍及多個項目,所以我看不到上升的問題,遠遠達)預裝我們提供的數據服務類的列表和GetService可以簡單地翻譯成新的插件,孟清湘。

+0

查詢是一個紅色的鯡魚。你的問題是,有些東西試圖連接到查詢返回的`Testimonial`實例上的`PropertyChanged`事件。您必須在調用FindTestimonial的地方發佈代碼。 – Gabe 2011-02-15 13:37:55

回答

0

好了,如下的解決方案是非常簡單的:

  • dbml設計師

  • 保存所有拆下Testimonial類,然後建立所有

  • 拖動Testimonial表格Server Explorer

  • 保存所有,然後建立所有

雖然這解決了我的問題,它並沒有告訴我,或者幫助我推斷爲什麼發生這種情況。如果有人想進一步闡述這個問題,那麼我不會無知的事實,所以請這樣做。