I was following the Contoso University tutorial on the asp.net website and it all works well. My next step was to replicate some of the things on my own new website. I have added an EntityDataSource that works:
<asp:EntityDataSource ID="ProductTypeEntityDataSource" runat="server"
ConnectionString="name=MyWebsite2011Entities"
DefaultContainerName="MyWebsite2011Entities" EnableFlattening="False"
EntitySetName="product_type">
And according to the tutorial it is a good idea to replace the ConnectionString and DefaultContainerName with a ContextTypeName.
"In the markup for the EntityDataSource control, remove the ConnectionString and DefaultContainerName attributes and replace them with a ContextTypeName="ContosoUniversity.DAL.SchoolEntities" attribute. This is a change you should make every time you create an EntityDataSource control, unless you need to use a connection that is different from the one that's hard-coded in the object context class."
That worked fine for me in the tutorial where they had a:
<asp:EntityDataSource ID="StudentsEntityDataSource" runat="server"
ContextTypeName="ContosoUniversity.DAL.SchoolEntities"
EnableFlattening="False"
EntitySetName="People"
EnableDelete="True" EnableUpdate="True">
</asp:EntityDataSource>
The difference for me (besides the project name) is that my entity model is not placed in a DAL folder. Instead I accepted the Visual Web Developer's default folder name recommendation. I believe it was "App_Code". But the ContextTypeName="MyWebsite2011.App_Code.MyWebsite2011Entities" doesn't work. When I start the browser, it complains that the type MyWebsite2011.App_Code.MyWebsite2011Entities could not be read.
<asp:EntityDataSource ID="ProductTypeEntityDataSource" runat="server"
ContextTypeName="MyWebsite2011.App_Code.MyWebsite2011Entities"
EnableFlattening="False" EntitySetName="product_type">
How do I find the correct ContextTypeName to put in? As I said, the ConnectionString and DefaultContainerName worked, so I guess the MyWebsite2011Entities is ok. Any hints would be appreciated because I don't know the naming convention or what to look for.
Open up the .cs file in which the Context is declared, and look at text immediately after the namespace
declaration. That's your class's namespace. Your ContextTypeName should be <namespace>.<classname>
(without the <> brackets, of course.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With