【发布时间】:2012-09-25 02:18:44
【问题描述】:
我正在使用 Entity Framework 和 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 Lead : Company
{
public Lead()
{
this.Status = 1;
this.IsQualified = false;
}
public Nullable<short> Status { get; set; }
public Nullable<bool> 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; }
}
}
【问题讨论】:
-
我们需要更多关于您的
DbContext的信息 -
我已经添加了上下文类代码。请检查我的问题。
-
将
public DbSet<Lead> Leads { get; set; }添加到CRMWebContainer。这可能对你有用。
标签: asp.net-mvc entity-framework entity-framework-4 entity-framework-4.1 entity-relationship