mapping relations.

Oct 28, 2012 at 11:31 AM

I'm having problems mapping relations.  I come from Hibernate as an ORM, and have troubles "adapting" i think...

Suppose I have a Customer entity, a Destination entity, an Order and OrderItems entities .

Each order has *one* customer and can have an *optional* destination, and one or more OrderIrtems.

Assuming the primary keys are all integer, how would I map this?

Coming from Hibernate I would map Customer and Destination as attributes in the Order entity, and OrderItems as an List<OrderItems> in Order.

Then if I don't have a Destination to set I would just leave it as null.

If I map this way in OpenNetCF.ORM, the foreing keys are not being set in the Insert method.

So i tried to map the foreing keys as integers in the Order entity, leaving the Customer attribute as a read only "placeholder".

This sorts of work, but if I don't set a Destination I get errors in the OnInsert method (since the array that holds the Destination property has only one null element).

The error occurs in the 

foreach (var element in valueArray as Array) 

loop, since element would be set as null.

I know I'm mapping the whole thing wrong.... Can anyone give a pointer on how to fix this?

Please is pretty urgent.  

Thanks

Coordinator
Oct 28, 2012 at 6:49 PM

Can you provide me a small database with some populated sample data?  I can then work out an example for retrieving what you're after.  Us the link on my name to the left to contact me.

Oct 28, 2012 at 8:50 PM

I sent you a message with the link to download the database.

The table I'm trying to insert into is called "Ordini" (orders)... Table Clienti is Customers, and Filiali is Destination (which would be the optional foreign key).

If you need any more info just let me know.

Thank you.