Connection lost with sdf file in a mvc project

88 views Asked by At

I´m starting to learn mvc with the tutorial MVC Music Store v3.0b. The code download from mvcmusicstore.codeplex.com Works fine. Now I´m trying the same example but using my own model.

My connectionstring in my web.config file is:

<connectionStrings>
   <add name="PlanetStampEntities" 
       connectionString="Data Source=|DataDirectory|MvcPlanetStamp.sdf"                    providerName="System.Data.SqlServerCe.4.0"/>
</connectionStrings>

Configuration for connecting with sdf file

The problem is that I can´t access to data stored in the class SampleData.cs under Models folder.

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

namespace MvcPlanetStamp.Controllers
{
    public class StoreController : Controller
    {
        PlanetStampEntities storeDB = new PlanetStampEntities();

        public ActionResult Index()
        {
            var tematicas = storeDB.Tematicas.ToList();
            return View(tematicas);
        }

    }
}

var tematicas never get results. But I have records in my class SampleData.cs

public class SampleData : DropCreateDatabaseIfModelChanges<PlanetStampEntities>
    {
        protected override void Seed(PlanetStampEntities context)
        {
            var tematicas = new List<Tematica>
            {
                new Tematica { Nombre = "Modernismo" },
                new Tematica { Nombre = "Alhambra" },
                new Tematica { Nombre = "Hollywood" },
                new Tematica { Nombre  = "Dibujos" },
                new Tematica { Nombre = "Montañas" },
            };
   ----

Finally, the code for my class PlanetStampsEntities.cs is:

using System.Data.Entity;

namespace MvcPlanetStamp.Models
{
    public class PlanetStampEntities : DbContext
    {
        public DbSet<Sello> Sellos { get; set; }
        public DbSet<Tematica> Tematicas { get; set; }
        public DbSet<Pais> Paises { get; set; }
    }
}

Table Selloes in the tree seems wrong. My class is Sello.cs. Where this name Selloes could be created?

Thank you

1

There are 1 answers

0
BSG On

Change your table name in .sdf file from Selloes to Sello