C# ICollection不会作为字段添加到实体框架中,为什么?

C# ICollection不会作为字段添加到实体框架中,为什么?,c#,sql,entity-framework,C#,Sql,Entity Framework,因此,由于它不构成该字段,我无法添加到日志中,因为它不存在。有人可以向我解释如何获取表以添加ICollection日志吗?ICollection logs不是一个字段。 它是从logs表填充的内存中的集合 public class User { [Key] public string userID { get; set; } public string username { get; set; } public virtual ICollection<Log

因此,由于它不构成该字段,我无法添加到日志中,因为它不存在。有人可以向我解释如何获取表以添加ICollection日志吗?

ICollection logs不是一个字段。 它是从logs表填充的内存中的集合

public class User
{
    [Key]
    public string userID { get; set; }
    public string username { get; set; }
    public virtual ICollection<Log> logs { get; set; }
    public User() { }
}
 public override void Up()
 {
        CreateTable(
            "dbo.Logs",
            c => new
                {
                    logID = c.String(nullable: false, maxLength: 128),
                    logString = c.String(),
                    logDatetime = c.DateTime(nullable: false),
                    User_userID = c.String(maxLength: 128),
                })
            .PrimaryKey(t => t.logID)
            .ForeignKey("dbo.Users", t => t.User_userID)
            .Index(t => t.User_userID);

        CreateTable(
            "dbo.Users",
            c => new
                {
                    userID = c.String(nullable: false, maxLength: 128),
                    username = c.String(),
                })
            .PrimaryKey(t => t.userID);

    }