Guywain
Guywain

Reputation: 13

ICollection<T> will not be added as a field in the Entity Framework, Why?

public class User
{
    [Key]
    public string userID { get; set; }
    public string username { get; set; }
    public virtual ICollection<Log> logs { get; set; }
    public User() { }
}

This is my class that I use for my DbSet<User> but the initial migration only picks up the userID and userName

 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);

    }

So because it does not make that field, I cannot add to the logs because its non-existent can anyone explain to me how to get the table to add the ICollection<Logs> logs?

Upvotes: 0

Views: 83

Answers (1)

Kirsten
Kirsten

Reputation: 18066

ICollection logs is not a field. It is an in memory collection that gets populated from the logs table.

Upvotes: 1

Related Questions