1

我创建了一个新的 asp.net MVC3 应用程序(互联网应用程序),然后我添加了一个具有 3 个类的新模型:

public class BizCard
{
    [Required]
    public string BizCardID { get; set; }

    [Required]
    public string Name { get; set; }

    public string Address { get; set; }

    public List<string> PhoneNumbers { get; set; }

    [Required]
    [DataType(DataType.EmailAddress)]
    public string Email { get; set; }

    public BizType type { get; set; }

    public List<BizService> OfferedServices { get; set; }

    public string Description { get; set; }
}

public class BizType
{
    public int BizTypeID { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public double Price { get; set; }
}

public class BizService 
{
    public int BizServiceID { get; set; }
    public List<BizType> AllowedBizTypes { get; set; }
    public string Name { get; set; }
}

之后,我创建了一个新控制器,使用模板“具有读/写操作和使用实体框架的视图的控制器”,我将模型类设置为“BizCard”,并将数据上下文类设置为一个名为“商务数据库”。我期待得到一个名为 BizDB 的新类,它继承自 DbContext 并包含 3 个 DbSet 实例:

DbSet<BizCard>, DbSet<BizType>, DbSet<BizService>. 

尽管如此,我只上了一个课:

DbSet<BizCard>.

我错过了什么吗?

4

1 回答 1

0

您正在使用 EF Code First 方法执行此操作。

1. So, you have to create a context class which should inherit DbContext containing required models as DbSet

2. Build the solution. Otherwise it will not be displayed at controller creation

然后您可以使用必要的模型及其 dbcontext 创建控制器。

于 2012-05-22T06:48:15.287 回答