Subsonic 3 and table relationships

150 Views Asked by At

I have something like this:

Order order = new Order();
Item item = new Item();
order.Items.Add(item);
order.Save();

How can I do this with Subsonic? The method that refere to a related table is IQueryable.

2

There are 2 best solutions below

0
On

You have three options:

  1. Set the foreign key in Item to the id of your Order object and save both.
  2. Create a partial class which has a method "AddItem", encapsulating this functionality
  3. Modify the T4 templates to allow you to do this automatically; unfortunately this feature doesn't come out of the box yet.

The advantage with Subsonic is that it is flexible, however you occasionally have to fill some of the gaps yourself.

0
On

If you are programming something like a shopping cart you can abstract that out into it's own class that can handle marrying the objects together. I personally think it works better than modify the generated objects.