3

おそらく簡単に解決できる一般的なエラーが発生しますが、その方法がわかりません。これが私が受け取るメッセージです。

列名が無効です。[ ノード名 (存在する場合) = Extent1、列名 = Blog_BlogId ]

説明:現在の Web 要求の実行中に未処理の例外が発生しました。エラーの詳細とコード内のどこでエラーが発生したかについては、スタック トレースを確認してください。

例外の詳細: System.Data.SqlServerCe.SqlCeException: 列名が無効です。[ ノード名 (存在する場合) = Extent1、列名 = Blog_BlogId ]

これは私のエンティティを表す私のクラスです:

public class BlogContext : DbContext
{
    public BlogContext()
        : base("SqlCeServices")
    {

    }

    public DbSet<User> Users { get; set; }

    public DbSet<Blog> Blogs { get; set; }

    public DbSet<Post> Posts { get; set; }

    public DbSet<Category> Categories { get; set; }

    public DbSet<Tag> Tags { get; set; }
}

[Table("aspnet_Users")]
public class User
{
    [Required]
    public Guid ApplicationId { get; set; }

    [Required]
    public Guid UserId { get; set; }

    [Required]
    public string UserName { get; set; }

    [Required]
    public string LoweredUserName { get; set; }

    public string MobileAlias { get; set; }

    [Required]
    public bool IsAnonymous { get; set; }

    [Required]
    public DateTime LastActivityDate { get; set; }
}

public class Blog
{
    [Key]
    public int BlogId { get; set; }

    [Required]
    public string Name { get; set; }
    public string Url { get; set; }
    public int Rating { get; set; }

    public virtual ICollection<User> Editors { get; set; }

    public virtual ICollection<Post> Posts { get; set; }
}

public class Post
{
    [Key]
    public int PostId { get; set; }
    [Required, MaxLength(200)]
    public string Title { get; set; }
    public string Content { get; set; }
    public string Abstract { get; set; }
    public DateTime DateCreated { get; set; }
    public DateTime DateLastEdited { get; set; }

    public virtual User UserId { get; set; }

    public virtual ICollection<Category> Categories { get; set; }
    public virtual ICollection<Tag> Tags { get; set; }

    public virtual Blog BlogId { get; set; }
}

public class Category
{
    [Key]
    public int CategoryId { get; set; }
    [Required, MaxLength(200)]
    public string Title { get; set; }
    public string Description { get; set; }

    public virtual ICollection<Post> Posts { get; set; }

    public virtual Category ParentCategory { get; set; }

    public virtual Blog BlogId { get; set; }
}

public class Tag
{
    [Key]
    public int TagId { get; set; }
    [Required, MaxLength(200)]
    public string Title { get; set; }

    public virtual Blog BlogId { get; set; }
}
4

3 に答える 3

1

試すことができます... ForeignKeyアノテーション

public virtual int BlogId { get; 設定; }

[ForeignKey("BlogId ")] public virtual ブログ ブログ { get; 設定; }

于 2016-02-15T18:50:06.437 に答える
1

BlogId が Blog オブジェクト自体ではなく、関連する Blog への FK を参照するように Post クラスを変更することを検討してください。実際の Blog オブジェクトを参照する新しいプロパティ Blog を追加します。

public class Post
{
    [Key]
    public int PostId { get; set; }
    [Required, MaxLength(200)]
    public string Title { get; set; }
    public string Content { get; set; }
    public string Abstract { get; set; }
    public DateTime DateCreated { get; set; }
    public DateTime DateLastEdited { get; set; }

    public virtual User UserId { get; set; }

    public virtual ICollection<Category> Categories { get; set; }
    public virtual ICollection<Tag> Tags { get; set; }

    public virtual int BlogId { get; set; }
    public virtual Blog Blog { get; set; }
}
于 2012-07-02T00:04:49.520 に答える
0

DBから接続を切り離し、アプリケーションに関連するアプリデータを削除して再構築し、再試行してください。うまくいきました。

于 2015-01-06T05:25:33.110 に答える