ASP.NET Web Forms Application Using Entity Framework 4.0 Database First

The Contoso University application created by the first of two Web Forms tutorial series at Continues to be provided alongside version 2 so that it can be used as a starting point for working through the second tutorial series.

4.5 Star
147,667 times
Add to favorites
E-mail Twitter Digg Facebook
  • Avoid duplicate records
    2 Posts | Last post April 29, 2014
    • Hi,
      Actually I have downloaded your project and I must say this is a very good project specially for beginners (like me).
      I was editing the student name and found that I can enter duplicate records and there is no validation available for that. Can you please help me to implement the validation so that I would not be able to enter a duplicate new record and also I should not be able to update any existing record (if same student is already exist).
    • To make requests for new topics to cover in samples or tutorials, see this web site:
  • how to configure the web.config file for Enitity Framework connection
    2 Posts | Last post March 28, 2014
    • I put your code on window2008 iis server and it throw the error in web.config for 
      following errors .
      ArgumentException: Format of the initialization string does not conform to specification starting at index 0.]
         System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) +6374602
         System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +253
         System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +134
         System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) +440
         System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName) +84
         ContosoUniversity.DAL.SchoolEntities..ctor() in C:\VS2010TrainingKit\ASP.NET Web Forms Application Using Entity Framework 4.0 Database First\C#\ContosoUniversity\DAL\SchoolModel.Designer.cs:45
      when I and run in local machine it works fine. I need to test my deployment for my project same situation as using your project in our department IIS server. How to resolve the issue in sql connection string in web.config file.
    • This sounds like a deployment issue rather than an issue with the project code. I'd recommend looking at one of our deployment tutorials, such as
      There's an entry in the Troubleshooting tutorial in that series for your error message that might be helpful:
  • How is the database setup?
    4 Posts | Last post November 15, 2013
    • I would like to know how the database is acting like portable here?
      What do I need to make my ASP.NET application behave in this portable manner?
    • The application uses a LocalDB database that is stored in an .mdf file in the App_Data folder. If you use Visual Studio templates to create MVC or Web Forms projects, by default they specify a LocalDB database for the membership database. It's portable in that it gets copied with the project, but you can't use it when you deploy to production because LocalDB doesn't work with IIS. For an overview of SQL Server editions, see
    • Hello,
      I would like to create a project with this template : " web forms application" (c#).
      As known, this template build automatically a local database.
      I need to use my personal database (after added to it Membership tables) and from it, add an EF model to the project.
      The problem is how to configure the web.config ?
      I got this error :
      " Unable to find the requested .Net Framework Data Provider.  It may not be installed."
      just after adding the EF model.
      After some search, i noticed that maybe the problem is in the connection string with ( and
      My web.config :
          <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-testapp-20131104233223;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-testapp-20131104233223.mdf" />
        <add name="DBSampleEntities"  connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=DBSample;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
       <!-- membership  -->
          <membership defaultProvider="DefaultMembershipProvider">
              <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DBSampleEntities" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      How to configure the web.config ?
      thanks a lot, albert
    • The database is portable only in the sense that you can copy the project and it goes with the project because it's a file in the App_Data folder.  Most hosting providers don't run SQL Express and you wouldn't typically use SQL Express UserInstance in production. For more information about deploying a web project with a database to a production environment, see 
  • Should I be using VB Web Express 2010?
    6 Posts | Last post August 03, 2013
    • Hi
      I am starting with VB Web Express 2012 - only worked with VB6 before (& SQL db)
      I don't find  "ASP.NET Web Application template" - only empty Web site, Web Forms site, same with Razor and Dynamic Entities . . .
      I have tried them all and yet I cannot find NavigationMenu even searching through each project?
      Also I installed SQLExpress 2005, but when I clicked on the AppData, it returned an error message saying that I needed to make a new connection?
      Any ideas?
    • The tutorial was written for VS 2010 and EF 4.0. VS 2012 has different templates and uses EF 5 by default.
    • Hi Tom
      Eventually (!) I removed 2012 and installed 2010 . . .
      and it all works perfectly!  :)
      Thanks so much
      A question from tutorial 10 - 
      Earlier you created a student statistics grid for the About page that showed the number of students for each enrollment date. The code that does this in HomeController.cs uses LINQ:
      var data = from student in db.Students
                 group student by student.EnrollmentDate into dateGroup
                 select new EnrollmentDateGroup()
                     EnrollmentDate = dateGroup.Key,
                     StudentCount = dateGroup.Count()
      How does this still work when the Students table is no longer there, having been replaced by the Persons table?
    • and looking at the difference between LINQ and SQL, does LINQ have significant benefits?
      (I ask only in that I am familiar with SQL queries)
    • On the value of LINQ, see this MSDN page:
      In the earlier tutorial, Code First maps the Student entity to the Student table.  In the later tutorial, the Student entity has been changed so that it derives from the Person entity, and from this Code First knows to look in the Person table for student data.  Your code can remain the same, but EF looks in different database tables for the data depending on how the entity is configured. 
    • very good congratulations
  • Unable to Load Project in Visual Studio 2010 Express
    2 Posts | Last post March 13, 2012
    • Is it not possible to load this application in VS Express edition, please help, thanks
    • The application does work in Visual Web Developer Express.  Make sure you have service pack 1 installed.
  • Great
    1 Posts | Last post December 08, 2011
    • Thank you for this code
      Twitter @asherjawad