有运行选定发生器错误。尝试重建项目 [英] There was an error running the selected generator . try rebuilding the project

查看:93
本文介绍了有运行选定发生器错误。尝试重建项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我创建了脚手架,并添加模型类,然后我得到这些错误的有运行选定生成一个错误。请尝试重建项目

我有三个模型类:

1.Department.CS

2.Designation.cs

3.CompanyDBContext.cs

数据库:我在数据库中的两个表,1部(DEPTID,DEPTNAME,说明)
                                         2.称号(desgtID,desgName,描述)

目标: - 我要为这些场景创建一个视图页面。像这样

表格(文本框)+部门名称(下拉列表框)+指定名称(下拉列表框)中插入名称

1.Department.CS

 命名空间mvcAppraisalSystem.Models
{
  公共类系
  {
    [键]
    公众诠释DEPTID {搞定;组; }
    公共字符串DEPTNAME {搞定;组; }
    公共字符串描述{搞定;组; }
  }
 }

2.Designation.cs

 命名空间mvcAppraisalSystem.Models
{
   公共类名称
   {
      [键]
      公众诠释desgID {搞定;组; }
      公共字符串desgName {搞定;组; }
      公共字符串描述{搞定;组; }
   }
 }

3.CompanyDBContext.cs

 命名空间mvcAppraisalSystem.Models
 {
   公共类CompanyDBContext:的DbContext
   {
      公共DbSet< CompanyDBContext> {部门获得;组; }      公共DbSet< CompanyDBContext>名称{搞定;组; }
   }
 }


解决方案

这是你可以改变连接字符串连接字符串的问题,你的的DbContext 名状波纹管在文件的的web.config 的:

 <&是connectionStrings GT;
  <添加名称=MovieDBContext的connectionString =数据源=(的LocalDB)\\ V11.0; AttachDbFilename = | DataDirectory目录| \\ ASPNET-MVCmove-20140616082808.mdf;初始目录= ASPNET-MVCmove-20140616082808;集成安全性=真的providerName =System.Data.SqlClient的/>
< /&是connectionStrings GT;

有关的类:

 使用系统;
使用System.Data.Entity的;
命名空间MVCmove.Models
{
  公共类电影
  {
    公众诠释ID {搞定;组; }
    公共字符串名称{搞定;组; }
    公众的DateTime RELEASEDATE {搞定;组; }
    公共字符串Default1Genre {搞定;组; }
    公共十进制价格{搞定;组; }
  }
  公共类MovieDBContext:的DbContext
  {
    公共DbSet<电影及GT;电影{搞定;组; }
  }
}

When I create the Scaffold and add the Model class then I am getting these error "There was an error running the selected generator . try rebuilding the project"

I have three Model class :

1.Department.CS

2.Designation.cs

3.CompanyDBContext.cs

Database : I have two table in database, 1. Department(deptID,deptName,Description) 2. Designation(desgtID,desgName,description)

Objective :- I want to create one view page for these scenario. Like this

Insert Name of Form (TextBox) + Department Name (Dropdown list box) + Designation Name (Dropdown list box)

1.Department.CS

namespace mvcAppraisalSystem.Models
{
  public class Department
  {
    [Key]
    public int deptID { get; set; }
    public string deptName { get; set; }
    public string Description { get; set; }
  }
 }

2.Designation.cs

namespace mvcAppraisalSystem.Models
{
   public class Designation
   {
      [Key]
      public int desgID { get; set; }
      public string desgName { get; set; }
      public string description { get; set; }
   }
 }

3.CompanyDBContext.cs

 namespace mvcAppraisalSystem.Models
 {
   public class CompanyDBContext : DbContext
   {
      public DbSet<CompanyDBContext> Departments { get; set; }

      public DbSet<CompanyDBContext> Designations { get; set; }
   }
 }

解决方案

This is the problem with the connection string you can change the connection string with your DbContext name like bellow on the file web.config:

<connectionStrings>
  <add name="MovieDBContext" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MVCmove-20140616082808.mdf;Initial Catalog=aspnet-MVCmove-20140616082808;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

For the class:

using System;
using System.Data.Entity;
namespace MVCmove.Models
{
  public class Movie
  {
    public int ID { get; set; }
    public string Title { get; set; }
    public DateTime ReleaseDate { get; set; }
    public string Default1Genre { get; set; }
    public decimal Price { get; set; }
  }
  public class MovieDBContext : DbContext
  {    
    public DbSet<Movie> Movies { get; set; }
  }
}

这篇关于有运行选定发生器错误。尝试重建项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆