I have looked in to one of the solution you provided for unable to connecting to the SQL Server 2008 in mvc4..I followed your answer but even though i am getting error.
public class videoDBContext : DbContext
{
static videoDBContext()
{
Database.SetInitializer<videoDBContext>(null);
}
public videoDBContext()
: base("Name=videoDBContext")
{
}
public DbSet<Video> Videos { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new VideoMap());
}
}
domain class
public class Video
{
public int Id { get; set; }
public string Description { get; set; }
}
Mapping class as
public class VideoMap : EntityTypeConfiguration<Video>
{
public VideoMap()
{
// Primary Key
this.HasKey(t => t.Id);
// Properties
this.Property(t => t.Description)
.IsRequired()
.HasMaxLength(50);
// Table & Column Mappings
this.ToTable("Video");
this.Property(t => t.Id).HasColumnName("Id");
this.Property(t => t.Description).HasColumnName("Description");
}
}
Controller action as
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
using (videoDBContext context = new videoDBContext())
{
var list = **context.Videos.ToList();**
}
return View();
}
I am getting error near the line:
Line 20: var s = context.Videos.ToList();
web.config
file is
<add name="videoDBContext"
connectionString="metadata=res://*/Models.xx.csdl|res://*/Models.xx.ssdl|res://*/Models.xx.msl;provider=System.Data.SqlClient;provider connection string="data source=servername;initial catalog=xx.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Please provide the solution. where am I going wrong? And sorry if it is silly or making you to inconvenience.