I have the following table declared
namespace RLSBCWebSite.Domain.Entities { [Table( Name = "tblFixtures" )] [DisplayColumn( "Date", "Date", false )] public class Fixture { [HiddenInput( DisplayValue = false )] [Column( IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert )] public int FixtureID { get; set; } [Required( ErrorMessage = "Please select Male, Female or Mixed" )] public string Gender { get; set; } ...... more columns public IEnumerable<ValidationResult> Validate( ValidationContext validationContext ) { if (((ScoreFor > 0) || (ScoreAgainst > 0)) && (!String.IsNullOrEmpty( Comments ))) yield return new ValidationResult( "Please complete either ScoreFor & ScoreAgainst or Comments!", new[] { "Comments" } ); } } } My DbContext is as follows:
namespace RLSBCWebSite.Domain.Entities { public class RLSBCWebSiteDb : DbContext { public DbSet<Officer> tblOfficers { get; set; } public DbSet<Fixture> tblFixtures { get; set; } public DbSet<CompetitionWinner> tblCompetitionWinners { get; set; } } } My Web.Config has:
<connectionStrings> <add name="RLSBCWebSiteDb" connectionString="data source=MAINPC\SQLEXPRESS;Initial Catalog=RLSBCWebSite;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings> My contoller code is:
RLSBCWebSiteDb rlsbcWebSite = new RLSBCWebSiteDb(); [HttpPost] public ActionResult CreateFixture(Fixture fixture) { if (ModelState.IsValid) { rlsbcWebSite.tblFixtures.Add( fixture ); rlsbcWebSite.SaveChanges(); return RedirectToAction( "MensResults", new { id = fixture.MatchDate.Year.ToString() } ); } return View( fixture ); } When I try and save the entry, I get an SQL UpdateException with the following error message when the .SaveChanges() statement is executed.
Invalid object name 'dbo.Fixtures'.
Why is it trying to update a table called Fixtures? Surely, it should be updating tblFixtures.