Bookstore model

I am developing a solution. I want to simulate the 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 is the best way to model it so that it can be moved both in the direction

1) From collection to book (i.e. if collection is selected, find all categories, subcategories and books under that.)

2) From Book to Collection (i.e. if a book is selected, it should be able to find which subcategory, category and collection it belongs to)

+2


a source to share


2 answers


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() { }
}

      

+1


a source


Looks like you need a carved wood. Alternatively, just use almost any valid relational database halfway through.



0


a source







All Articles