实体框架Migrationbuilder.CreateTable跳过模型类

时间:2018-08-16 15:08:47

标签: c# entity-framework-core

我有一个使用MVC和EF Core的ASP.net 2.0应用程序。我只是在将所有数据放在一起的初期(而且我是编码新手),因此可能存在一些不良做法或我可以做得更好的事情。

我有一个从SiteUser模型类继承的Employee模型类。是的,它们不是非常简单的类。当我使用EF迁移进行首次首次迁移时,生成的代码并未为Employee类创建CreateTable方法.Employee类位于Snapshot文件中,但不在create表中。

这些类中的任何内容是否会突出显示它们为什么不生成? 我已从项目中删除EF,然后重新安装,但未成功。

SiteUser模型类

using System;
using System.ComponentModel.DataAnnotations;

namespace Intranet_MVC_Core.Models
{
    public class SiteUser : Person
    {
        public string ObjectIdentifier { get; set; }
        public SiteUserStatus SiteUserStatus { get; set; }
        public UserType UserType { get; set; }
        public string PhotoURL { get; set; }

        public string StartupPage { get; set; }
    }
}

员工模型课

using System;
using System.ComponentModel.DataAnnotations;

namespace Intranet_MVC_Core.Models
{
    public class Employee : SiteUser
    {
        public string UserName { get; set; }

        public string WorkMobile { get; set; }

        public string Address1 { get; set; }
        public string Address2 { get; set; }
        public string City { get; set; }
        public string State { get; set; }
        public string Zip { get; set; }
        public string Country { get; set; }

        public string Notes { get; set; }
        public string EmergencyContact { get; set; }
        public string EmergencyContactNumber { get; set; }
        public string EmergencyContactRelationship { get; set; }
        public bool Active { get; set; }
        public string InOutMemo { get; set; }
        public DateTime InOutReturnTime { get; set; }
        public String InOutLocation { get; set; }

        public string AlternateEmail { get; set; }
        public string PersonalEmail { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        public string ProfileImage { get; set; }

        public bool ProjectManager { get; set; }
        public DateTime BirthDate { get; set; }

        //Foreign Key
        public virtual EmployeeType EmployeeType { get; set; }

        public virtual EmployeeTitle EmployeeTitle { get; set; }
        public virtual InOutStatus InOutStatus { get; set; }
    }
}

DBContext类(//在EF迁移中生成,// x不生成

using Intranet_MVC_Core.Models;
using Microsoft.EntityFrameworkCore;

namespace Intranet_MVC_Core.Context
{
    public class CRMContext : DbContext
    {
        public CRMContext()
        {
        }

        public CRMContext(DbContextOptions<CRMContext> options) : base(options)
        {
        }

        public DbSet<ActivityCode> ActivityCodes { get; set; }//
        public DbSet<ActivityItem> ActivityItem { get; set; }//
        public DbSet<Alert> Alerts { get; set; }//
        public DbSet<AlertStatus> AlertStatuses { get; set; } //
        public DbSet<AlertType> AlertTypes { get; set; }//
        public DbSet<AppSetting> AppSettings { get; set; }//
        public DbSet<Asset> Assets { get; set; }//

        public DbSet<Company> Companies { get; set; }//
        public DbSet<CompanyType> CompanyTypes { get; set; }//
        public DbSet<Contact> Contacts { get; set; }//
        public DbSet<ContactStatus> ContactStatuses { get; set; }//
        public DbSet<Correspondence> Correspondences { get; set; }//

        public DbSet<Deliverable> Deliverables { get; set; }//
        public DbSet<Department> Departments { get; set; }//
        public DbSet<Discipline> Disciplines { get; set; }//

        public DbSet<Employee> Employees { get; set; }//x Not Generating in EF Migration Code
        public DbSet<EmployeeTitle> EmployeeTitles { get; set; }//
        public DbSet<EmployeeType> EmployeeTypes { get; set; }//
        public DbSet<EventAssignment> EventAssignments { get; set; }//
        public DbSet<EventTask> EventTasks { get; set; }//
        public DbSet<EventType> EventTypes { get; set; }//

        public DbSet<InOutStatus> InOutStatuses { get; set; }//

        public DbSet<JobStatus> JobStatuses { get; set; }//
        public DbSet<JobType> JobTypes { get; set; }//
        public DbSet<ProposalActivity> JobScopes { get; set; }//

        public DbSet<Lead> Leads { get; set; }//

        public DbSet<MarketingStep> MarketingSteps { get; set; }//

        public DbSet<NewsPost> NewsPosts { get; set; }//
        public DbSet<NewsPostTag> NewsPostTags { get; set; }//

        public DbSet<Project> Projects { get; set; }//
        public DbSet<ProjectType> ProjectTypes { get; set; }//
        public DbSet<Proposal> Proposals { get; set; }//
        public DbSet<Prospect> Prospects { get; set; }//
        public DbSet<ActivityItem> ProposalScopeItems { get; set; }//x Not Generating in EF Migration Code
        public DbSet<Prefix> Prefixes { get; set; }//

        public DbSet<SalesCampaign> SalesCompaigns { get; set; }//
        public DbSet<SalesMaterial> SalesMaterials { get; set; }//
        public DbSet<SalesType> SalesType { get; set; }//
        public DbSet<SiteUser> SiteUser { get; set; }//
        public DbSet<SiteUserStatus> SiteUserStatuses { get; set; }//
        public DbSet<UserType> UserTypes { get; set; }//

        public DbSet<WorkAssignment> WorkAssignments { get; set; }//
    }
}

0 个答案:

没有答案