“Horking

 

HORK Sample: Creating data with HORK

There are two ways to create data using HORK.
The second way to create data is to create instances of each entity and add them to the database table graph.
In the following example, we will create a Contact with an Address and then create an Order for the contact with 2 OrderItems:

            Contact contact = new Contact();
            contact.ContactId = Guid.NewGuid();
            contact.FirstName = "Bob";
            contact.LastName = "Roberts";
            contact.Business = false;
            contact.MainPhone = "310-700-2123";
            contact.Email = "bob@bobroberts.org";
            
Address address = new Address(); address.AddressId = Guid.NewGuid(); address.AddressContactId = contact.ContactId; address.Address1 = "742 Evergreen Terrace"; address.City = "Springfield"; address.PostalCode = "54321"; address.Country = "United States";
contact.AddAddress(address);

Order order = new Order(); order.OrderId = Guid.NewGuid(); order.OrderContactId = contact.ContactId;

contact.AddOrder(order);

OrderItem orderItem = new OrderItem(); orderItem.OrderItemId = Guid.NewGuid(); orderItem.OrderId = order.OrderId; orderItem.ItemNumber = "77765"; orderItem.ItemDescription = "Red Socks"; orderItem.Quantity = 24;

order.AddOrderItem(orderItem);

orderItem = new OrderItem(); orderItem.OrderItemId = Guid.NewGuid(); orderItem.OrderId = order.OrderId; orderItem.ItemNumber = "77402"; orderItem.ItemDescription = "Technical Book"; orderItem.Quantity = 1;

order.AddOrderItem(orderItem);

HORKRepository repo = new HORKRepository(); repo.Update(contact); repo.Save();

When working with the entity table graph it is necessary to use HORKRepository to save the data. The HORKRepository class understands how to execute queries in the proper sequence.
If you have used many ORM's you are aware that regardless of the underlying technology, the ORM programmer has to know the table relationships to understand how to manipulate the entity table graph.