3
這裏是我的表結構和上下文:如何生成具有多個集合的表的控制器?
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
using System.Linq;
using System.Web;
namespace AspnetIdentitySample.Models
{
public class Employee : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
public virtual ICollection<MyTask> MyTasks { get; set; }
public virtual ICollection<Customer> Customers { get; set; }
}
public class MyTask
{
public int MyTaskId { get; set; }
public string Description { get; set; }
public DateTime OldDate { get; set; }
public DateTime NewDate { get; set; }
public bool IsDone { get; set; }
public virtual Employee User { get; set; }
}
public class Customer
{
public int CustomerId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public virtual Employee Employee { get; set; }
}
public class MyDbContext : IdentityDbContext<Employee>
{
public MyDbContext()
: base("DefaultConnection")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Change the admin of the table to be Users instead of AspNetUsers
modelBuilder.Entity<IdentityUser>()
.ToTable("Employee");
modelBuilder.Entity<Employee>()
.ToTable("Employee");
}
public DbSet<MyTask> MyTasks { get; set; }
public DbSet<Customer> Customers { get; set; }
public DbSet<Employee> Employees { get; set; }
}
}
當我試圖創建一個使用實體框架的CRUD控制器,它顯示了以下錯誤消息。任何幫助,將不勝感激。 :)
我不在我的應用程序中的用戶表,但。 –
請將您的整個Dbcontext課程發佈在您的問題中。 – Marco
增加了...... :) –