ASP.NET MVC Application Using Entity Framework Code First

A Visual Studio 2013 project which shows how to use the Entity Framework 6 in an ASP.NET MVC 5 web application project, using the Code First development approach.

C# (541.9 KB)
 
 
 
 
 
4.4 Star
(172)
598,600 times
Add to favorites
2/11/2017
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • git repository
    1 Posts | Last post May 31, 2017
    • Do you have this in git in order to create a branch ? I would like add more feature for this demo in order to be used for academic purpose .
      
      Thanks 
  • Uploading a multi file on visual studio mvh-code first
    1 Posts | Last post May 12, 2017
    • hello,
      
      When u upload let's say 4 picture at the same time, only one of
      The pictures goes in to the database and the rest of
      The pictures end up in the right folder in the project. How can I get all of them
      In the database? How should the table look like? 
      
      Hoop that you guys understand the question and can help me putt with this it's really urgent.
      
      Thanks 
      
  • Enrollment
    3 Posts | Last post March 05, 2017
    • Tom,
      Nice demo. The enrollment does not show up on the nav bar , when I add it or try to access it by http://localhost:41787/Enrollment I get an error" HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable" I see there is an enrollment class but no controller. I tried adding the controller  still get the error. Any suggestions?
    • The sample app doesn't have an enrollments page.  See the tutorial linked to on the description page for samples of the pages included in the project and instructions for how to add controllers and views.
    • Thanks Tom
      I created one with a controller . It works great. Excellent sample just what I need to learn many to many relations.
  • error while display student pages
    2 Posts | Last post January 07, 2017
    • Hello,
      I already try but get some error when i open student pages like this:
      'A network-related or instance-specific error occurred while establishing a connection to SQL Server'.
      I actually download sql server management studio but still can't connect to database 
      How to solve it?
    • Hi
      
      It sounds like the database tables have not populated. What version of Visual Studio are you using?
      
      A couple of things:
      1. Can you open the pages when you run locally? If not, then the database isn't being created and you need to make sure you follow the instructions on using the Nuget Package manager to restore packages and then close \ start Visual Studio and run update-database from the NPM console (see description tab). Also, make sure you have updated the web.config accurately. It should be:
      
          <add name="SchoolContext" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=ContosoUniversity2;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
       
      
      2. If so, and it is an Azure issue, make sure you have enabled the firewall on the Azure SQL Server for your client IP address.
      
      Regards
      
      Graham  
  • IncompatibleException in Entity framework
    2 Posts | Last post December 13, 2016
    • Am using vs 2015. When i tried to run this project, it is giving the error : An exception of type 'System.Data.ProviderIncompatibleException' occurred in EntityFramework.dll but was not handled in user code.
      
      
      So i tried in PMC : update-database , go again below exception : 
      
      Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or assembly 'EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 
      or one of its dependencies. The system cannot find the file specified."
      At E:\Practice Projects\Getting Started with Entity Framework 5 using MVC 4\C#\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:431 char:5
      
      i have changed the connecting string from v11.0  to MSSQLLocalDB.
      
      Please let me know what i have to do to solve this issue. 
      
      
    • This sample project is for EF 6 and MVC 5.
  • Is there any possibility to run this solution in VS2012?
    2 Posts | Last post October 17, 2016
    • Hi Tom,
        Thank u for this instruction.
      I have VS2012 only. Is there any possibility to run this with some update? 
    • It might but I haven't validated that myself.  You could use the free VS 2015 Community Edition to do the tutorial, while continuing to use VS 2012 in your other work.  Everything you learn about EF and MVC would apply in VS 2012 as well as 2015.
  • Creating DB using VS2015
    5 Posts | Last post October 17, 2016
    • Using Visual Studio Community 2015RC the app could not create and load the database.
      
      As explained in this link http://bit.ly/1GpaxN4 starting with this VS2015, the team is moving away from version dependent connection strings. That means, once you adopt VS 2015, you have the option of using a version independent  connection string moving forward. 
      To fix this issue for now, and future versions of Visual Studio, replace the version dependent connection string (e.g. “v11.0”) with “MSSQLLocalDB”.
      
      So open the Web.config file and change the connectionString as follows:
      
      From:
      connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=ContosoUniversity2;Integrated Security=SSPI;"
      
      To:
      connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=ContosoUniversity2;Integrated Security=SSPI;"
      
    • Great example !
    • Great
    • That's great.Thanks
    • Nice!
  • Relationship between Instructor and OfficeAssignment
    2 Posts | Last post September 23, 2016
    • Hi Tom, 
      Thank you for all the detaill instructions. 
      I have one query that why it's   
       public virtual OfficeAssignment OfficeAssignment { get; set; } 
      , rather than  public virtual ICollection<OfficeAssignment> OfficeAssignment { get; set; } 
      in Instructor class, since it's 1:N relationship between instructor and officeassignment.
      
      Thanks.
    • The relationship is 1 to zero or 1; in this model you can't have multiple office assignments for an instructor.
  • Get Error when access student page
    2 Posts | Last post September 09, 2016
    • Hi Tom, I get error when access student page
      
      Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified
      
      Source Error:
      
      
      Line 19:         public ActionResult Index()
      Line 20:         {
      Line 21:             return View(db.Students.ToList());
      Line 22:         }
      Line 23: 
      
      
      Source File: c:\users\juang\documents\visual studio 2015\Projects\ContosoUniversity\ContosoUniversity\Controllers\StudentController.cs    Line: 21 
      
      I'm new in .NET MVC, please help me to can resolve the error
      
      Thanks
    • Make sure you follow all of the instructions under the Getting Started section, including the PMC commands. If that doesn't help try following the tutorial to see what happens when you build from scratch, as that may help pinpoint where the error is coming from.
  • Identity 2.0 Plans?
    3 Posts | Last post August 01, 2016
    • Hi,
      I was wondering if there were any future plans of implementing login entity framework functionality using Identity 2.0 ?
      
      Thanks :-)
    • Probably not for this example.  The tutorial series is already quite long at 12 substantial tutorials, and a similarly long one could be done for identity itself.  The more topics you try to do in one tutorial, the less well you can do for any one of the topics.  For identity tutorials, see http://asp.net/identity.
    • It is interesting.
1 - 10 of 72 Items