我需要一些關於Visual Studio生成的ADO.NET中強類型數據集的專家建議。這裏是細節。先謝謝你。有關如何在.NET的N層應用程序中使用強類型數據集的問題
我想寫一個N層應用程序,其中表示層是在C#/ Windows窗體中,業務層是Web服務,數據訪問層是SQL數據庫。
因此,我使用了Visual Studio 2005,並在解決方案中創建了3個項目。
項目1是數據訪問層。在此我使用了Visual Studio數據集生成器來創建一個強類型數據集和表格適配器(用於測試我在Northwind的customers表格上創建的)。數據集稱爲NorthWindDataSet,裏面的表是CustomersTable。
項目2有Web服務,它只公開了1個方法,它是GetCustomersDataSet。這使用project1庫的表適配器填充數據集並將其返回給調用者。爲了能夠使用NorthWindDataSet和表格適配器,我添加了對項目1的引用。
項目3是一個勝利表格應用程序,它使用Web服務作爲參考並調用該服務來獲取數據集。
在構建本申請中,在PL的過程中,我添加到項目中的1和形式的負載以上生成的I調用web服務,並從Web服務指定所接收到的數據集的數據集的引用到這個數據集。但我得到的錯誤:
Cannot implicitly convert type 'PL.WebServiceLayerReference.NorthwindDataSet' to 'BL.NorthwindDataSet' e:\My Documents\Visual Studio 2008\Projects\DataSetWebServiceExample\PL\Form1.cs
這兩個數據集是相同的,但因爲我加了來自不同位置的引用,我收到上面的錯誤,我認爲。
所以,我所做的是我添加了項目1(它定義了數據集)對項目3(UI)的引用,並使用Web服務獲取DataSet並分配到正確的類型,現在項目3(具有Web窗體)運行,我得到下面的運行時異常。
System.InvalidOperationException: There is an error in XML document (1, 5058). ---> System.Xml.Schema.XmlSchemaException: Multiple definition of element ' http://tempuri.org/NorthwindDataSet.xsd:Customers ' causes the content model to become ambiguous. A content model must be formed such that during validation of an element information item sequence, the particle contained directly, indirectly or implicitly therein with which to attempt to validate each item in the sequence in turn can be uniquely determined without examining the content or attributes of that item, and without any information about the items in the remainder of the sequence.
我想這可能是因爲一些交叉引用錯誤。
我的問題是,有沒有辦法使用Visual Studio生成的DataSets,以便我可以在所有圖層中使用相同的DataSet(用於重用),但將表適配器邏輯與數據訪問層分開,以便前端是從Web服務中抽象出來的?
如果我有手寫代碼,我會放棄數據集生成器給出的優點,並且如果以後添加了列,我需要手動添加它等,因此我想盡可能使用Visual Studio嚮導。
謝謝。我可以在哪裏瞭解更多關於上述主題的內容?此外,這是一個遺留項目,所以將現有代碼(大代碼庫)移動到新範例可能會有所幫助,但我可能沒有很大的靈活性,但移動時可能沒有太多... – 2010-04-05 04:35:25
我在我的評論中添加了鏈接 – vittore 2010-04-05 21:52:57
感謝您的支持三分球! – 2010-04-08 07:52:38