Hi Matt
Long post. Sorry.
A one to many relationship example in the Northwind database is Customers:Orders. I am asking if there is any way to deal with these related tables as an object. E.g:
- Code: Select all
Customer customer = new Customer();
customer.LoadByPrimaryKey(\"QUICK\")
customer.Orders.Rewind();
do
{
Debug.WriteLine(customer.Orders.OrderDate);
} while (customer.Orders.MoveNext());
It seems like I need to do the following to get (say) the dates of the customers orders:
- Code: Select all
Customers customer = new Customers();
customer.LoadByPrimaryKey(\"QUICK\");
Orders order = new Orders();
order.Where.CustomerID.Value = customer.CustomerID;
order.Query.Load();
order.Rewind();
do
{
Debug.WriteLine(order.OrderDate);
} while (order.MoveNext());
This is fairly unimportant in a simple database like Northwind, but when dealing with a real database, the coding becomes substantial. Imagine entities with lots of 1:m and several m:m relationships, then it is looking like a lot of application code is needed.
If I used a view for this example, I would maybe use the Northwind.[Orders Qry] view:
- Code: Select all
OrdersQry customer = new OrdersQry();
customer.Where.CustomerID.Value = \"QUICK\";
customer.Query.Load();
do
{
Debug.WriteLine(customer.OrderDate);
} while (customer.MoveNext());
As you see, this view will contain repeated information from the Customers table for each of the (28) orders.
Again, with just one or two of these in a database, then it is manageable, but usually one has many more such relationships to deal with. Often a table could have several such 1:m relationships, multiplying the number of rows that a view would return.
On a related subject (I raised this in
another post ), a significant relationship in my databases is 1:1 or m. i.e. a table *must* have at least one row in a second table. If I could create a generated object from a view of two such interdependent tables, then EO would be very useful for me. I already have these views with triggers that manage updating both tables correctly.
At the moment, I need to temporarily rename the view, then create a table that looks like view and is named the same. The EO BusinessObject template then creates my object using this stand-in table. I can then rename the table (or delete it) and return the view back to its original name and all is then working splendidly. I can use the view as though it were a table.
The INSTEAD OF trigger on the view is called when the daab sprocs are called and thus updates the tables appropriately, ignoring the daab sprocs.
The triggers lock this solution to SQL Server, so it would be much better to have the object generation templates do this for me and use daab sprocs that understand which columns are in which tables instead of view triggers. Does that sound hard? I will have a go at customising the templates if you think it is possible and a reasonable thing to do.