views:

184

answers:

3

I've created many-to-many relationship with ADO.NET with extra order fields in the middle table.

So I have...

Customers
-customer_id
-customer_name

Orders
-order_id

Customers_to_Orders
-customer_id
-order_id
-seq

And now I don't really know how to add new orders to customers with specyfing order, any suggestions?

A: 

Create the order first.

Get the ID back for the order.

Then, create the link from the customer to the order.

richardtallent
A: 

you add the order to orders table first, and then add it to customer_to_orders preferably in one transaction.

if you're worried about the seq - it can be either identity or you can calculate "next seq" by querying customers_to_orders before adding new data.

Dani
A: 

I tried code like this

var customers_to_orders = new customers_to_orders();
customers_to_orders.customer_id = 1;
customers_to_orders.order_id = 1;
customers_to_orders.seq = 1;
_db.AddTocustomers_to_orders(customers_to_orders);

But it gives me

Entities in 'myEntities.customers_to_orders' participate in the 'customers_to_orders_ibfk_1' relationship. 0 related 'customers' were found. 1 'customers' is expected.

I'm using mysql with connector version 6.2 if thay change something.

Inez

related questions