Book Store Model
I am developing a solution. I want to model following structure
Collection 1
Category 1
Sub Category 1.1
Book 1
Book 2
Book 3
Sub Category 1.2
Book 1
Category 2
Sub Category 2.1
Book 2
Sub Category 2.2
Book 3
Sub Category 2.3
Book 4
Category 3
Sub Category 3.1
Book 4
)
What it the best possible way to mode开发者_Python百科l it so that it can be traversed in both the direction
1) From collection to Book (i.e. if collection is selected find all the categories, sub categories, and books under that.)
2) From book to collection (i.e. if book is selected should be able to find which sub category, category and collection it belongs to)
Here's a basic model for your application.
alt text http://ruchitsurati.net/myfiles/bookstore.png
public class Book
{
public Category ParentCategory { get; set; }
public Book() { }
}
public class Category
{
public CategorySet SubCategories { get; set; }
public BookSet Books { get; set; }
public Category()
{
SubCategories = new CategorySet();
Books = new BookSet();
}
}
public class Collection
{
public CategorySet Categories { get; set; }
public Collection() {
Categories = new CategorySet();
}
}
public class BookSet : System.Collections.ObjectModel.Collection<Book>
{
public BookSet() { }
}
public class CategorySet : System.Collections.ObjectModel.Collection<Category>
{
public CategorySet() { }
}
public class CollectionSet : System.Collections.ObjectModel.Collection<Collection>
{
public CollectionSet() { }
}
It sounds like what you need is a threaded tree. Alternatively, just use almost any halfway reasonable relational database.
精彩评论