Asp.net mvc 无法添加使用从其他类继承的类的控制器
我使用的是实体框架和MVC3,我的问题是,如果该类从另一个类继承,我就无法构建控制器 例如: 这是基类Asp.net mvc 无法添加使用从其他类继承的类的控制器,asp.net-mvc,entity-framework,entity-framework-4,entity-framework-4.1,entity-relationship,Asp.net Mvc,Entity Framework,Entity Framework 4,Entity Framework 4.1,Entity Relationship,我使用的是实体框架和MVC3,我的问题是,如果该类从另一个类继承,我就无法构建控制器 例如: 这是基类 using System; using System.Collections.Generic; namespace CRMEntities { public partial class Company { public int Id { get; set; } } } 这是领班(儿童) 使用系
using System;
using System.Collections.Generic;
namespace CRMEntities
{
public partial class Company
{
public int Id { get; set; }
}
}
这是领班(儿童)
使用系统;
使用System.Collections.Generic;
命名空间属性
{
公共部分类领导:公司
{
公共铅()
{
这个状态=1;
this.IsQualified=false;
}
公共可空状态{get;set;}
公共可空IsQualified{get;set;}
}
}
当我尝试在下面添加控制器时,出现错误
上下文类代码
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
namespace CRMEntities
{
public partial class CRMWebContainer : DbContext
{
public CRMWebContainer()
: base("name=CRMWebContainer")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<Employee> Employees { get; set; }
public DbSet<Contact> Contacts { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<Location> Locations { get; set; }
public DbSet<Task> Tasks { get; set; }
public DbSet<EventInfo> EventInfoes { get; set; }
public DbSet<Opportunity> Opportunities { get; set; }
public DbSet<Comment> Comments { get; set; }
public DbSet<Document> Documents { get; set; }
public DbSet<LoginInformation> LoginInformations { get; set; }
public DbSet<CRMLog> CRMLogs { get; set; }
public DbSet<EntitySharing> EntitySharings { get; set; }
public DbSet<EntityFlagging> EntityFlaggings { get; set; }
public DbSet<EntityTagging> EntityTaggings { get; set; }
public DbSet<EntitySubscribing> EntitySubscribings { get; set; }
public DbSet<Compapny> Compapnies { get; set; }
}
}
使用系统;
使用System.Data.Entity;
使用System.Data.Entity.Infrastructure;
命名空间属性
{
公共部分类CRMWebContainer:DbContext
{
公共CRMWebContainer()
:base(“name=CRMWebContainer”)
{
}
模型创建时受保护的覆盖无效(DbModelBuilder modelBuilder)
{
抛出新代码FirstException();
}
公共数据库集雇员{get;set;}
公共数据库集联系人{get;set;}
公共数据库集产品{get;set;}
公共数据库集位置{get;set;}
公共数据库集任务{get;set;}
公共数据库集事件信息{get;set;}
公共数据库集机会{get;set;}
公共DbSet注释{get;set;}
公共数据库集文档{get;set;}
公共数据库集登录信息{get;set;}
公共DbSet CRMLogs{get;set;}
公共数据库集实体共享{get;set;}
公共数据库集EntityFlaggings{get;set;}
公共数据库集实体标记{get;set;}
公共数据库集实体订阅{get;set;}
公共DbSet Compapnies{get;set;}
}
}
MVC AddController窗口检查要添加的模型类型的属性数据库集。
您应该像VicentedalEncar所说的那样,添加到您的CRMWebContainer
:
[Obsolete("Design only", true)]
public DbSet<Lead> Leads { get; set; }
[过时(“仅设计”,正确)]
公共数据库集引线{get;set;}
请记住,您不应该在代码中使用此属性(这就是为什么要使用过时属性),因为获取潜在客户的正确方法是使用:
var leads = Companies.OfType< Lead >();
var leads=公司。类型();
MVC AddController窗口检查要添加的模型类型的属性数据库集。
您应该像VicentedalEncar所说的那样,添加到您的CRMWebContainer
:
[Obsolete("Design only", true)]
public DbSet<Lead> Leads { get; set; }
[过时(“仅设计”,正确)]
公共数据库集引线{get;set;}
请记住,您不应该在代码中使用此属性(这就是为什么要使用过时属性),因为获取潜在客户的正确方法是使用:
var leads = Companies.OfType< Lead >();
var leads=公司。类型();
我们需要有关您的DbContext
的更多信息。我已经添加了上下文类代码。请检查我的问题。将public DbSet Leads{get;set;}
添加到CRMWebContainer
。这可能对您有用。我们需要有关您的DbContext
的更多信息。我已添加了上下文类代码。请检查我的问题。将public DbSet Leads{get;set;}
添加到CRMWebContainer
。那可能对你有用。