Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Entity Framework Code First - Able to migrate and update database but no table created

$
0
0

Hi, before this, I am able to create table after I run

"enable-migrations" 

"add-migration abc"

"update-database"

After I add the foreign key, I can't see my new tables but I can run the above command with no error. Can someone tell what can possible gone wrong?

These are my 3 classes for the model

public class Employee
    {
        /// <summary>
        /// Gets or sets Name.
        /// </summary>
        public int Id { get; set; }

        [Required]
        [Display(Name = "Full Name")]
        public string Name { get; set; }

        [Required]
        [Display(Name = "Date of Birth")]
        public string DateOfBirth { get; set; }

        [Required]
        [Display(Name = "Employement Type")]
        public string EmploymentType { get; set; }

        [Required]
        [Display(Name = "Basic Salary")]
        public int BasicSalary { get; set; }

        public virtual ICollection<Attendance> Attendances { get; set; }
    }
public class Attendance
    {
        public int Id { get; set; }

        public int WorkHour { get; set; }

        public DateTime WorkDate { get; set; }

        public int EmployeeID { get; set; }
        public virtual Employee Employee { get; set; }

    }
 public class PayrollReport
    {
        public int Id { get; set; }

        [Required]
        [Display(Name = "Net Salary")]
        public int NetSalary { get; set; }

        public int EmployeeID { get; set; }
        public virtual Employee Employee { get; set; }
    }

and my dbcontext code is:

 public class myDBContext : DbContext
    {
        public myDBContext() : base("myDB")
        {
        }

        public DbSet<Employee> Employees { get; set; }
        public DbSet<Attendance> Attendances { get; set; }
        public DbSet<PayrollReport> PayrollReports { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

        }


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>