Currently, I am trying to pull information from a database using the EntityFramework. As such, I have connected to the proper database:
<add name="ChartConn" connectionString="Data Source=****;Initial Catalog=****;User ID=****;Password=****;" providerName="System.Data.SqlClient" />
where the asterisks are filled in with the correct personal information for that database.
The issue is when I attempt to pull information from this database with the following in my controller:
public ActionResult Index()
{
var q = (from c in db.ChannelMaps
select c.LABEL).ToList();
return View(q);
}
and the following in the model, CHANNELMAP:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
using System.Linq;
using System.Web;
namespace ChartApp.Models
{
public class CHANNELMAP
{
[Key]
public int CHANNELNUM { get; set; }
public int COLUMNID { get; set; }
public string LABEL { get; set; }
public string RAWUNITS { get; set; }
public double? MULT { get; set; }
public double? ADDER { get; set; }
public int? DATATYPEID { get; set; }
public int? OPCODEID { get; set; }
public decimal? OPVALUE { get; set; }
public int? SITEID { get; set; }
public string DASNAME { get; set; }
}
public class ChannelMapContext : DbContext
{
public ChannelMapContext()
: base("ChartConn")
{
Database.SetInitializer<Models.ChannelMapContext>(null);
}
public DbSet<CHANNELMAP> ChannelMaps { get; set; }
}
}
I get an error: Invalid object name dbo.CHANNELMAPs
, that points to the first line (from c in db.ChannelMaps
) of my linq query in my controller. This is strange because my model's name is CHANNELMAP, so I am unsure as to why I am getting an error for an invalid name for an object that I have not used. What is causing this error? I have tried changing the name of my model numerous times, as well as triple-checking to make sure my connection string and property names are all set up accordingly.