0

我开始通过 MVC Music Store v3.0b 教程学习 mvc。从 mvcmusicstore.codeplex.com 下载的代码工作正常。现在我正在尝试相同的示例,但使用我自己的模型。

我的 web.config 文件中的连接字符串是:

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

连接 sdf 文件的配置

问题是我无法访问存储在 Models 文件夹下的 SampleData.cs 类中的数据。

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 永远不会得到结果。但我在我的班级 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" },
            };
   ----

最后,我的类 PlanetStampsEntities.cs 的代码是:

使用 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; }
    }
}

树中的表 Selloes 似乎是错误的。我的课是 Sello.cs。这个名字 Selloes 可以在哪里创建?

谢谢

4

1 回答 1

0

将 .sdf 文件中的表名从 Selloes 更改为 Sello

于 2015-06-08T08:03:48.663 回答