[dblinq] Dblinq insert 3 rows, 1 child with two different parent tables

26 views
Skip to first unread message

wind cloud

unread,
Apr 24, 2010, 5:02:40 AM4/24/10
to DbLinq
Hi! I just wonder if it is my misunderstanding of Linq usage or if
it's really a lacking in DbLinq.

I am using DbLinq 0.20.1 with MySql and run into a situation, say I
want to insert 1 row with 2 columns each referencing 2 parent tables.

e.g.

Parent Table: Table_A, Table_B.
Child Table: Table_C, with Column_A_ID reference to Table_A, and
Column_B_ID reference table_B.

Now when I insert a new row into Table_C, obviously I am going to
execute Table_C.InsertOnSubmit(), if that row was referencing to an
existing entry in BOTH Table_A and Table_B, then things are fine.
However, if both Table_A and Table_B lacks that entry, then DbLinq
will bug me not conforming to the foreign key relationship. However,
If I create a row in the parent table, say Table_A, then insert the
row into Table_C, then it bugs me about constraint on Table_B, same
for inserting to Table_B first, then it bugs me about the constraint
on Table_A. I am wonder if I'd done something wrong, or DbLinq cannot
insert rows with more than 1 references.

e.g.
Dim context = New MyDbContext()
Dim table_a = New Table_A()
Dim table_b = New Table_B()
Dim table_c = New Table_C()
table_c.Table_A = table_a
table_c.Table_B = table_b

context.Table_C.InsertOnSubmit(table_c) ''Not working after
SubmitChanges due to constraint of Table_A
context.Table_A.InsertOnSubmit(table_a) 'Not working after
SubmitChanges due to constraint of Table_B
context.Table_B.InsertOnSubmit(table_b) 'Not working after
SubmitChanges due to constraint of Table_A

so how exactly do I do it in DbLinq if I want to make 3 entries, 1
child and 2 parent with the child referencing both parents.

Thanks.

--
You received this message because you are subscribed to the Google Groups "DbLinq" group.
To post to this group, send email to dbl...@googlegroups.com.
To unsubscribe from this group, send email to dblinq+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dblinq?hl=en.

Anders

unread,
Apr 24, 2010, 8:40:33 AM4/24/10
to DbLinq
On Apr 24, 11:02 am, wind cloud <wwindcl...@gmail.com> wrote:
> Hi! I just wonder if it is my misunderstanding of Linq usage or if
> it's really a lacking in DbLinq.
>
> I am using DbLinq 0.20.1 with MySql and run into a situation, say I
> want to insert 1 row with 2 columns each referencing 2 parent tables.

Thank you for reporting the problem. It seems that the problem is
closely related to issue 246 and I have added a test-case, inspired by
your problem but using the Northwind schema, to the bug:
http://code.google.com/p/dblinq2007/issues/detail?id=246

One workaround would, I guess, be to call SubmitChanges after calling
InsertOnSubmit for the two child tables, table_a and table_b, and
again after calling InsertOnSubmit for table_c. I realize that this is
not a real solution, e.g. since it won't execute all inserts in the
same transaction.

--
Anders
Reply all
Reply to author
Forward
0 new messages