我的页面正确加载数据,但是当我添加:
.Include(x => x.User);
我明白了:
Invalid column name 'User_UserId'.
Invalid column name 'User_UserId'.
Invalid column name 'User_UserId'.
Invalid column name 'User_UserId'.
public partial class User
{
public Guid UserId { get; set; } //Primary key
public virtual ICollection<UserOpenId> UserOpenIds { get; set; }
public virtual ICollection<UserRecipeNote> UserRecipeNotes { get; set; }
public virtual ICollection<UsersInRole> UsersInRole { get; set; }
public virtual Blog Blog { get; set; }
public virtual ICollection<UserFilter> Preferences { get; set; }
}
public partial class UserOpenId
{
public int Id { get; set; } //Primary key
public Guid UserId { get; set; } //Foreign key
public virtual User User { get; set; }
}
其他用户属性与UserOpenId相同,其中Id为主键,UserId为外键。
当我添加迁移时,SQL关系看起来都是正确的:
CreateTable(
"dbo.User",
c => new
{
UserId = c.Guid(nullable: false),
//other properties
})
.PrimaryKey(t => t.UserId);
CreateTable(
"dbo.UserOpenId",
c => new
{
Id = c.Int(nullable: false, identity: true),
UserId = c.Guid(nullable: false),
//other properties
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.User", t => t.UserId, cascadeDelete: true)
.Index(t => t.UserId);
我已经配置了这样的关系:
modelBuilder.Entity<User>()
.HasMany(e => e.UserOpenIds)
.WithRequired(e => e.User)
.WillCascadeOnDelete(false);
我认为死亡的黄色屏幕与关系有关,我哪里出错?