Creating own POCO classes wont work. ERROR Schema specified is not valid
When I try to create my own POCO classes I get this error. This is only when I got a list of some kind or acsosiation like in this case the Author got Books. But it works great when I use the T4. I kinda like to create my own classes because then I could add my AddBook() to it.. so I highly appreciate if anybody know why..
Schema specified is not valid. Errors:
The relationship 'EworkModel.AuthorBook' was not loaded because the type 'EworkModel.Book' is not available.
The following information may be useful in resolving the previous error:
The required property 'AuthorId' does not exist on the type 'EntityWork.Model.Book'.
my classes look like this
public class Author
{
public virtual int AuthorId { get; set; }
public virtual string Name { get; set; }
public List<Book> Books { get; set; }
}
public class Book
{
public virtual int BookId { get; set; }
public virtual string Title { get; set; }
public virtual Author Author { get; set; }
}
private ObjectSet<Author> _authors;
private ObjectSet<Book> _books;
public EntityWorkContext()
: base("name=EworkEntities", "EworkEntities")
{
_authors = CreateObjectSet<Author>();
_books = CreateObjectSet<Book>();
ContextOptions.LazyLoadingEnabled = true;
}
public ObjectSet<Author> Authors
{
get
{
return _authors;
}
}
public ObjectSet<Book> Books
{
get
{
return _books;
}
}
public void Save()
开发者_如何转开发 {
SaveChanges();
}
Seems like EF is looking for the foreign key in your Book entity. Maybe you did not exclude foreign key mapping.
Anyway, if you use the t4 generated POCOs you can still add custom methods like AddBook() by creating a partial class, because the t4 generated classes are partial.
精彩评论