아마도 쉽게 해결할 수있는 공통적 인 오류가 발생합니다. 단서가 없습니다. 이것은 내가받는 메시지입니다.열 이름이 유효하지 않습니다.
열 이름이 잘못되었습니다. [노드 이름 (있는 경우) = Extent1, 열 이름 = Blog_BlogId]
설명 : 현재 웹 요청을 실행하는 동안 처리되지 않은 예외가 발생했습니다. 오류 및 코드에서 시작된 위치에 대한 자세한 정보는 스택 추적을 검토하십시오.
예외 정보 : 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; }
}
언제 예외가 발생합니까? 어떤 쿼리? –
BlogContext를 통해 사용자에게 액세스하고 컬렉션을 목록으로 변환합니다. 이것은 표준 컨트롤러 스캐 폴드의 Index 액션에서 수행됩니다. –
"캐스트"는 실제로 ToList()를 사용하고 있음을 의미합니다. –