An exception of type 'System.Data.Entity.Core.EntityException' occurred in EntityFramework.SqlServer.dll but was not handled in user code

asp.net-mvc asp.net-mvc-4 entity-framework entity-framework-4 entity-framework-6

Question

I am new to ASP.NET MVC, I am facing this exception, the connection string looks perfect but still, the exception is raised, appreciate if anyone give me why is happening.

Thank you, men.

Model 1

namespace MVCTwice.Models
{
    public class StudentContext : DbContext
    {
        public DbSet<Student> studs { get; set; }
    }
}

Model 2

namespace MVCTwice.Models
{
    [Table("tblStudents")]
    public class Student
    {
        public int id { get; set; }
        public string name { get; set; }
        public string gender { get; set; }
        public string totalMarks { get; set; }
    }
}

action plan

public ActionResult Index()
        {
            StudentContext studentContext = new StudentContext();
            //Student emp = studentContext.studs.Select(emp=>emp.)
           List<Student> emp=studentContext.studs.ToList();

            return View(emp);
        }

View

@model MVCTwice.Models.Student
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div> 
        @Model.gender
        @Model.name
        @Model.id
        @Model.totalMarks

    </div>
</body>
</html>

Exception

enter image description here

ConnectionString

 <connectionStrings >
    <add
         name="myConnectionString"
         connectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=LoginInfo;Data Source=.\SQLEXPRESS"
         providerName="System.Data.SqlClient"/>
  </connectionStrings>
1
4
11/6/2016 12:59:16 AM

Popular Answer

ZZZ_tmp
4
3/28/2017 8:43:06 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow