簡體   English   中英

ICollection的 <T> 不會在實體框架中添加為字段,為什么?

[英]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() { }
}

這是我用於DbSet<User>類,但是初始遷移僅使用userID和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);

    }

因此,因為它不構成該字段,所以我無法添加到日志中,因為任何人都無法向我解釋如何獲取該表以添加ICollection<Logs> logs

ICollection日志不是一個字段。 它是一個從日志表填充的內存中集合。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM