实体
[ForeignKey("juchuId")]
public virtual TFzm004 juchuTFzm004 { get; set; }
/// <summary>
/// JUCHU_ID
/// </summary>
[Column("JUCHU_ID", TypeName = "numeric")]
public virtual decimal? juchuId { get; set; }
关联实体
/// <summary>
/// TFcd008
/// </summary>
[ForeignKey("juchuId")]
public virtual IList<TFcd008> TFcd008s { get; set; }
实体已经配置成可空 为什么生成的Migrations就变成非空了 如下
public partial class test1 : DbMigration
{
public override void Up()
{
DropIndex("dbo.T_FCD008", new[] { "JUCHU_ID" });
AlterColumn("dbo.T_FCD008", "JUCHU_ID", c => c.Decimal(nullable: false, precision: 38, scale: 0, storeType: "numeric"));
CreateIndex("dbo.T_FCD008", "JUCHU_ID");
}
public override void Down()
{
DropIndex("dbo.T_FCD008", new[] { "JUCHU_ID" });
AlterColumn("dbo.T_FCD008", "JUCHU_ID", c => c.Decimal(precision: 38, scale: 0, storeType: "numeric"));
CreateIndex("dbo.T_FCD008", "JUCHU_ID");
}
}
手动改Migrations能实现 但是400多个表呀。。这个到底是什么引起的呢 用的ABP框架
兄弟你上面的
[ForeignKey("juchuId")]
public virtual IList<TFcd008> TFcd008s { get; set; }
外键属性标错了吧,我实践了一下,导航属性可以为空的:
话不多说,贴代码
评论实体:
public class Comment:CreationAuditedEntity<Guid,User>
{
public virtual string Text{get;set;}
public virtual string UserName { get; set; }
public virtual Question Question { get; set; }
public virtual Guid QuestionId { get; set; }
public virtual ICollection<Answer> AnswerList { get; set; }
public Comment()
{
}
public Comment(string Text)
{
this.Text = Text;
}
}
回复实体:
public class Reply: CreationAuditedEntity<Guid, User>
{
public virtual string Text { get; set; }
public virtual int Depth { get; set; }
[ForeignKey("CommentId")]
public virtual Comment Comment { get; set; }
public virtual Guid? CommentId { get; set; }
[ForeignKey("ReplyToId")]
public virtual Reply ReplyTo { get; set; }
public virtual Guid? ReplyToId { get; set; }
public virtual bool IsReply { get; set; }
public virtual ICollection<Reply> Replays { get; set; }
}
然后运行程序包控制台运行:
add-migration xxxxx
然后再运行:
update-database
然后结果:
兄弟,你再试试看吧