Foreign Key Duplicate Entry Linqconnect MYSQL

Foreign Key Duplicate Entry Linqconnect MYSQL

Postby dklompmaker » Tue 11 Jan 2011 17:08

Hello,

I have recently purchased Linqconnect for mysql. The problem I am having is when I have a table with a foreign key relationship. And I insert an item on the first table, it inserts on the second table as well.

for instance.

Code: Select all
var query = from c in db.catagories
                    select c;

Catagory someCatagory = query.First();

Product p  = new Product();
p.catagory = someCatagory;

db.Products.InsertOnSubmit(p);
db.SubmitChanges();



In this scenario, the catagory is inserted along with the product. I just want the product inserted and the catagory just a reference for the foreign key id.

Can anyone help me with this?

Thank you!
dklompmaker
 
Posts: 3
Joined: Tue 11 Jan 2011 17:01

Postby StanislavK » Wed 12 Jan 2011 12:05

I've sent you a test project in a letter. In the sample, a row from the 'one' table of the one-to-many relation is selected, a new entity of the 'many' class is created and added to the corresponding collection of the 'one' entity. When submitting changes, a row is added only to the 'many' table in our environment.

Please specify what should be changed in the sample to reproduce the problem, or send us your test project.
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Postby dklompmaker » Wed 12 Jan 2011 15:18

I have further researched the problem and have found that somehow the relation is inserting a new record even though it has been set.

So take this example of three tables: Order, Orders_Products, Products

The Order table has an auto primary id.

The Orders_Products has an auto incrememt primary id, order_id, and product_id

The Products table just has a auto increment id and a name.

The Orders_Products table has a one to many relationship to both the order, and the products table.

When I do this
Code: Select all
OrdersProduct op = new OrdersProduct();
op.Order = CurrentOrder;
op.Product = SelectedProduct;

db.OrdersProducts.InsertOnSubmit(op);
db.SubmitChanges();


I am not sure why it is doing this. It inserts another version of the Product of which I referenced even though the product class clearly has its auto id set correctly to the correct reference.

I did receive the file you had sent me. I do not get the proble when there is only one relationship point to another table. But soon as I have on table that has two relationships to many. There is an issue.
dklompmaker
 
Posts: 3
Joined: Tue 11 Jan 2011 17:01

Postby StanislavK » Thu 13 Jan 2011 16:39

I've sent you a sample in a letter, please check that it was not blocked by your mail filter. We couldn't reproduce the problem with two one-to-many associations either; please specify what should be changed in the sample for this purpose.

If possible, please send us the script defining the tables you are using or a complete sample with which the issue can be reproduced.

Also, could you please specify the versions of dotConnect for MySQL and MySQL server you are using?
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48


Return to dotConnect for MySQL