简体   繁体   English

EF 6代码的第一列未创建

[英]EF 6 Code First one column is not created

I am using EF 6 Code First, I don't understand why one column is not created for a property of my Model. 我正在使用EF 6代码首先,我不明白为什么没有为我的模型的属性创建一列。

Here is the first class : 这是头等舱:

    public class Original
    {
    public int ID { get; set; }
    public string Nom { get; private set; }
    public Historique Historique { get; private set; }
    public Traduction Traduction { get; private set; }
    }

And here is the second class : 这是第二堂课:

   public class Traduction
   { 
    public int ID { get; set; }
    public Utilisateur Traducteur { get; private set; }
    public Original Original { get; private set; }
    public string Content { get; private set; }
   }

EF doesn't create the FK column for Traduction and Original. EF不会为Traduction和Original创建FK列。 (The Traduction table doesn't contains a FK column for Original and vice versa) but it perfectly creates all the other column and FKs. (“转导”表不包含“原始”的FK列,反之亦然),但它可以完美地创建所有其他列和FK。

I am playing with Fluent API to set up the relationships. 我正在使用Fluent API来建立关系。 I have tried both to rely on the automatic conventions, and to explicitly configure the relation with : 我试图既依赖于自动约定,又明确地使用以下方式配置关系:

   modelBuilder.Entity<Original>().HasRequired(o => o.Traduction).WithRequiredPrincipal(t=>t.Original).WillCascadeOnDelete(true);

But the columns are still not created. 但是仍然没有创建列。

Thank you for your help 谢谢您的帮助

Update 更新

I don't know if it is useful but I would like to add one information, my Dbset are defined like this in the context class : 我不知道它是否有用,但我想添加一个信息,我的Dbset在上下文类中是这样定义的:

public DbSet<Traduction> Traductions { get; set; }
public DbSet<Original> Originaux { get; set; }

"Originaux" if the French plural for "Originals". “ Originaux”如果将法语复数表示为“ Originals”。 However I have noticed that the Table created by EF is Named "Originals", and doesn't follow the name of the DbSet. 但是我注意到EF创建的表被命名为“ Originals”,并且没有遵循DbSet的名称。 I don't know, perhaps it might be a cause of the problem. 我不知道,也许这可能是问题的原因。

As Dismissile said, EF doesn't create an extra column to hold the foreign keys because it is a one-to-one relationship. 正如Dismissile所说,EF不会创建额外的列来容纳外键,因为它是一对一的关系。 This is a normal behaviour and nothing is actually wrong. 这是正常现象,实际上没有错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM