Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newbie question: Need help with ContextTypeName

Tags:

asp.net

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.

like image 646
Kasper Hansen Avatar asked May 21 '11 07:05

Kasper Hansen


1 Answers

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.)

like image 133
dlev Avatar answered Sep 28 '22 19:09

dlev