In this section, we want to work on a new content management, which will be the product of our website.
So first, what we have to do is we need to create a model for fact.
Let me close out the taps here inside the models project where we create our main model, which will
be product.
This will be of public class, and the first property will be the.
That is the primary key off the table.
Next, we need a string, which will be name of the product.
We will have another string for description.
And since our products will be books, we will have ISBN number and author for our books.
I will also make this name as a required property and rather than name a more meaningful will be to
call it title, then for our products.
We should have a list price of that book.
So if we're going to create a double, which will be list price, our requirements are a little bit
different for each product.
What people do is we can have a list price like we want to give them a special price on each product.
So along with a list price, we're going to create a new variable here, which will be the final price.
This will be the price if they want to buy just one product.
But we have special requirements that we will have special pricing if they are buying 50 books at a
time, which will be like a bulk order or if they order like concrete books, it will have even better
price.
So admin can set different prices for one single book, 50 or more and 100 or more books.
So Amazon has lots of configuration with this.
Next, we want to display an image for all of the books.
So let me just add a string here, which will be the wall of the image.
These properties are good enough for the product, but we have category and cover type, so our books
should have a foreign key relation to the category, add and cover type it.
Based on that, our book will have a category and cover type.
So how do we get that kind of mapping of foreign keys when we are using entity framework or if it's
pretty smart with all the mappings?
The mapping that we want here is product should have a category I.D. So that will create an integer
variable.
We will call this category.
Now, if you create a property here of category where we've counted as category, this will automatically
create a foreign key relation because if it's very smart, it knows that this is a navigation property
to the category class here.
And since the name of category, it is exactly same as category appended with an I.D., it will automatically
make category I.D. a foreign key.
So if we have to do the same thing with cover type.
So this will be cover type I.D. and the class here would be cover type where you want to make sure both
of these I.D. are required.
If you want to explicitly mention here that this Category ID is a foreign key to this category class.
You can do that with the foreign key data annotation.
We will have to add the using statement, but as I said before, this is not required.
If for some reason you had called this a category test, then this was required because it would not
automatically meant that it was able to map automatically.
Because if it is appended again, it is smart enough to link those properties automatically so that
our model is done for the product.
We have quite a few properties that we have created.
Let's continue in the next week, you.