我正在關注asp.net網站上的Contoso University教程,它一切正常。我的下一步是在我自己的新網站上覆制一些內容。我加入的作品的EntityDataSource:新手問題:需要關於ContextTypeName的幫助
<asp:EntityDataSource ID="ProductTypeEntityDataSource" runat="server"
ConnectionString="name=MyWebsite2011Entities"
DefaultContainerName="MyWebsite2011Entities" EnableFlattening="False"
EntitySetName="product_type">
而按照教程這是一個ContextTypeName更換的ConnectionString和DefaultContainerName一個好主意。
「在EntityDataSource控件的標記中,刪除ConnectionString和DefaultContainerName屬性,並用ContextTypeName =」ContosoUniversity.DAL.SchoolEntities「屬性替換它們。這是每次創建EntityDataSource控件時應該進行的更改,除非您需要使用與在對象上下文類中硬編碼的連接不同的連接。「
,在那裏他們有一個教程的工作對我罰款:
<asp:EntityDataSource ID="StudentsEntityDataSource" runat="server"
ContextTypeName="ContosoUniversity.DAL.SchoolEntities"
EnableFlattening="False"
EntitySetName="People"
EnableDelete="True" EnableUpdate="True">
</asp:EntityDataSource>
對我來說,區別(除了項目名稱)是我的實體模型不是放置在DAL文件夾中。相反,我接受了Visual Web Developer的默認文件夾名稱建議。我相信這是「App_Code」。但是,ContextTypeName =「MyWebsite2011.App_Code.MyWebsite2011Entities」不起作用。當我啓動瀏覽器時,它抱怨MyWebsite2011.App_Code.MyWebsite2011Entities類型無法讀取。
<asp:EntityDataSource ID="ProductTypeEntityDataSource" runat="server"
ContextTypeName="MyWebsite2011.App_Code.MyWebsite2011Entities"
EnableFlattening="False" EntitySetName="product_type">
如何找到放入的正確ContextTypeName?正如我所說的,ConnectionString和DefaultContainerName的工作,所以我猜MyWebsite2011Entities是好的。任何提示將不勝感激,因爲我不知道命名約定或尋找什麼。
ContextTypeName引用您的namespace.className而不是文件名。 – 2011-05-21 07:28:54