why in ORM(object relation model) Model in this sample foreignkey column publisher in book class is a class of publisher,while where we could use of a long type(in database publisher is foreignkey and Bigint)?
public class Publisher
{
[XmlAttribute]
public string Title { get; set; }
[XmlAttribute]
public string Address { get; set; }
}
public class Book
{
[XmlElement]
public Publisher Publisher { get; set; } ******
[XmlAttribute]
public string Title { get; set; }
[XmlAttribute]
public short PrintYear { get; set; }
[XmlAttribute]
public short Pages { get; set; }
[XmlAttribute]
public string ISBN { get; set; }
}
This is to make your life easier. In your database the table
BOOKhas aPublisherIdthat is a foreign key to the tablePUBLISHER. To avoid the need to write relational joins in your C# code as you need to do in SQL, yourBookclass has a property of the referenced typePublisher, so you can directly access it. This also conforms more to OOD principles.Example:
If your class
Bookonly had apublic int PublisherId {get;set;}, you would need the following code to get the publisher’sTitle:With the current
Bookclass, this is shorter and easier to read: