I know it's seems like a very newbie question but it's still confuse me how you can link objects within objects:
For example I have an objects of Book:
name
pages
publication Date
author
and so on.
But my question will be on the Author itself is an object so how will I be able to link author to this book inside the database I mean One Author can have a lot of books so it's not right to save to every book the full author object.
Thanks for your help
I tried to look for any answer on Stack Overflow, but it seems to be a concept relatively simple but not for me.
So this seems more a general C# question, so my answer will be with that in mind, if that is not correct then let me know.
So, you author could be as follows:
public class Author
{
public int Id{get;set;}
public string Name{get;set}
...
}
and your books could be:
public class Book{
public int Id{get;set;}
public int AuthorId{get;set;}
}
The Book.AuthorId would be the same Id the Author has, so you could then use this Id to get the Authors details such as name etc.
If i were to add this to an Umbraco site, or a general site I would probably use a code first approach, this allows you to have strongly typed classes (objects) within classes, so you when you get your Book, youll get your Author back as well. See here for some more details https://learn.microsoft.com/en-us/ef/ef6/modeling/code-first/workflows/new-database
Database link objects within objects C#
I know it's seems like a very newbie question but it's still confuse me how you can link objects within objects:
For example I have an objects of Book:
name pages publication Date author and so on.
But my question will be on the Author itself is an object so how will I be able to link author to this book inside the database I mean One Author can have a lot of books so it's not right to save to every book the full author object.
Thanks for your help
I tried to look for any answer on Stack Overflow, but it seems to be a concept relatively simple but not for me.
Hi Mani,
So this seems more a general C# question, so my answer will be with that in mind, if that is not correct then let me know.
So, you author could be as follows:
and your books could be:
The Book.AuthorId would be the same Id the Author has, so you could then use this Id to get the Authors details such as name etc.
If i were to add this to an Umbraco site, or a general site I would probably use a code first approach, this allows you to have strongly typed classes (objects) within classes, so you when you get your Book, youll get your Author back as well. See here for some more details https://learn.microsoft.com/en-us/ef/ef6/modeling/code-first/workflows/new-database
Lewis
Thank You so much Lewis Smith for giving suggestion to me
is working on a reply...