【问题标题】:Creating Controller For EF Model With Child Models Using Template使用模板为带有子模型的 EF 模型创建控制器
【发布时间】:2012-09-02 22:27:10
【问题描述】:

我的标题可能令人困惑,但这是我的问题。我是来自 ASP.net 和 Linq to Sql 的 EF 和 MVC4 的新手

所以我首先创建了代码模型,数据库看起来很棒,就像我写的一样。

//namespace Article.Models

public class ArticleContext : DbContext
{
    public DbSet<Article> Articles { get; set; }
    public DbSet<Group> Groups { get; set; }
    public DbSet<Category> Categories { get; set; }
    public DbSet<Dimension> Dimensions { get; set; }
}

public class Article
{
    public int ArticleId { get; set; }
    public string Name { get; set; }
    public int CategoryId { get; set; }
    public virtual Category Category { get; set; }
    public double Comission { get; set; }
    public string Link { get; set; }
    public virtual List<Group> Topics { get; set; }
}

public class Group
{
    public int GroupId { get; set; }
    public int ArticleId { get; set; }
    public virtual Article Article { get; set; }
    public string CategoryId { get; set; }
    public int AdTypeId { get; set; }
    public virtual Dimension Dimension { get; set; }
}

public class Category
{
    public int CategoryId { get; set; }
    public string Name { get; set; }

    public virtual List<Article> Articles { get; set; }
}

public class Dimension
{
    public int DimensionId { get; set; }
    public string Name { get; set; }
    public int Width { get; set; }
    public int Height { get; set; }
}

创建数据库后,我将连接字符串添加到网络配置中。

当我尝试制作控制器时,我可以使用 EF 模板为具有读/写操作和视图的类别和组制作它们,这没问题。

但是对于文章模型和组模型,我得到了同样的错误

但我每次都会收到以下错误

是我做错了什么还是在这种情况下无法使用读/写模板?

【问题讨论】:

    标签: entity-framework model controller asp.net-mvc-4


    【解决方案1】:

    看看这个问题及其答案。这可能会有所帮助。 stackoverflow.com/questions/7859611/could-not-load-file-or-assembly-publickeytoken-null

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多