Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

entity framework - Invalid column name 'Column' in EF Core Fluent API

I am trying to create a one-to-one relationship in EF Core using Fluent API but when I try to save the model it throws invalid column name exception.

public partial class Child
{
    public Guid? ParentId {get;set;} // this is the FK
    public virtual Parent {get;set;}
}

public partial class Parent
{
    public Guid Id {get;set;}
    public virtual Child {get;set;}
}

 entity.HasOne(d => d.Child)
         .WithOne(p => p.Parent)
         .HasForeignKey<Child>(d => d.ParentId)
         .HasConstraintName("FK_Parent_Child");

So when I try to save a Parent model to database I keep getting that ParentId is an invalid column name( it does actually exist in the database, and I also have the logger to debug SQL queries and it does point to the right table )

question from:https://stackoverflow.com/questions/65909468/invalid-column-name-column-in-ef-core-fluent-api

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...