2

我正在使用 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; }
    }
}
4

1 回答 1

0

MVC AddController 窗口检查您正在添加的 ModelType 的属性 DbSet。您应该像 vicentedealencar 所说的那样,添加到您的CRMWebContainer

[Obsolete("Design only", true)]
public DbSet<Lead> Leads { get; set; }

请记住,您不应在代码中使用此属性(这就是过时属性的原因),因为获取潜在客户的正确方法是使用:

var leads = Companies.OfType< Lead >();
于 2012-11-08T13:27:57.703 回答