Error in entity framework database

Posted by Klbaiju under ASP.NET MVC on 9/2/2014 | Points: 10 | Views : 551 | Status : [Member] | Replies : 2
Hi,

iam new to MVC.

iam trying to do database application using EF with code first

I create a new MVC internet application with name DataMigration.

next I added a class file in model

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using DAtaMigration.Models;

namespace DAtaMigration.Models
{
public class StudentInfo
{
[Key]
public int StudentID { get; set; }
public string StudentName { get; set; }
public string Address { get; set; }
}
}

***************************************

after build , added another class file in model

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;

namespace DAtaMigration.Models
{
public class StudentInfoContext:DbContext
{


public StudentInfoContext() : base("name=StudentInfoContext")
{

}

public DbSet<StudentInfo> StudentInfoes { get; set; }
}
}

*****************************************************

the i added a StudentInfoController with empty model class and datacontext

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DAtaMigration.Models;

namespace DAtaMigration.Controllers
{
public class StudentInfoController : Controller
{
//
// GET: /StudentInfo/
StudentInfoContext db = new StudentInfoContext();

public ActionResult Index()
{
return View(db.StudentInfoes.ToList());
}

}
}

************************************

finally added a view to index

@model IEnumerable< DAtaMigration.Models.StudentInfo>

@{
Layout = null;
}

<!DOCTYPE html>

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.StudentName)
</th>
<th>
@Html.DisplayNameFor(model => model.Address)
</th>
<th></th>
</tr>

@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.StudentName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Address)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.StudentID }) |
@Html.ActionLink("Details", "Details", new { id=item.StudentID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.StudentID })
</td>
</tr>
}

</table>
</div>
</body>
</html>
*****************************

when i run following error is showing

No connection string named 'StudentInfoContext' could be found in the application config file.

why it is showing error

Regards

Baiju




Responses

Posted by: Bandi on: 9/2/2014 [Member] [MVP] Platinum | Points: 25
Posted by: Bandi on: 9/2/2014 [Member] [MVP] Platinum | Points: 25

Login to post response