[英]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.