Chciałbym mieć tylko jeden klucz obcy UserId ale w migracji automatycznie pojawia się też User_Id, jak się tego pozbyć?
namespace JSW.DataAccess.Entities
{
public class Subscription : Entity<int>
{
public string Name { get; set; }
public int EmployeeQty { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public virtual User User { get; set; }
public int? UserId { get; set; }
}
}
namespace JSW.DataAccess.EntitiesConfigurations
{
class SubscriptionConfiguration : EntityTypeConfiguration<Subscription>
{
public SubscriptionConfiguration()
{
ToTable("Subscription");
HasKey(u => u.Id);
HasOptional(x => x.User).WithMany().HasForeignKey(x => x.UserId).WillCascadeOnDelete();
}
}
}
namespace JSW.DataAccess.Migrations
{
using System;
using System.Data.Entity.Migrations;
public partial class dssf : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.Subscription",
c => new
{
Id = c.Int(nullable: false, identity: true),
Name = c.String(),
EmployeeQty = c.Int(nullable: false),
StartDate = c.DateTime(nullable: false),
EndDate = c.DateTime(nullable: false),
UserId = c.Int(),
User_Id = c.Int(),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.User", t => t.User_Id)
.ForeignKey("dbo.User", t => t.UserId, cascadeDelete: true)
.Index(t => t.UserId)
.Index(t => t.User_Id);
CreateTable(
"dbo.User",
c => new
{
Id = c.Int(nullable: false, identity: true),
Login = c.String(nullable: false, maxLength: 100),
Name = c.String(),
PasswordHash = c.String(),
Email = c.String(),
Active = c.Boolean(nullable: false),
LastActivityDate = c.DateTime(),
PasswordChangeRequired = c.Boolean(nullable: false),
LastPasswordChangeDate = c.DateTime(),
SessionId = c.String(),
})
.PrimaryKey(t => t.Id);
}
public override void Down()
{
DropForeignKey("dbo.Subscription", "UserId", "dbo.User");
DropForeignKey("dbo.Subscription", "User_Id", "dbo.User");
DropIndex("dbo.Subscription", new[] { "User_Id" });
DropIndex("dbo.Subscription", new[] { "UserId" });
DropTable("dbo.User");
DropTable("dbo.Subscription");
}
}
}