tags:

views:

53

answers:

1

I'm just writing my first "Hello World" program using Subsonic, for which I've thrown together a simple little Customer/Invoice/InvoiceItem/Product database.

The connection was successfully made to the DB, and it generated all the right ActiveRecord classes. But for some reason, the Invoice class has a property called Customers, which returns a collection of Customer objects, even though the Invoice table has a CustomerID field which has a foreign key to the Customer table. I would have expected a Customer property returning a single Customer object.

Same thing is happening for all of my FKs. I must be doing something wrong - but what?

+1  A: 

That is expected behavior. The first (and only) item in the Invoice.Customers collection will be the foreign key related Customer object.

sparks
Why is that expected behavior? I'm coming from the built in Linq-To-SQL O/R Designer, and that generate relationships along the lines I've describedas "expected behavior". You have to admit that makes more logical sense, no? It's obvious there was some technical issue here that forced a rather kludgy workaround - but why?
Shaul
I'm not sure why this is how it was implemented in SubSonic 3. SubSonic 2 would generate an Invoice.Customer field as you mentioned. However, you can add this field yourself in the T4 templates.
sparks