insert problem on one to one relationship

insert problem on one to one relationship

Postby Partalakos » Mon 07 Mar 2011 19:30

Hello, i have two tables, account and account_other_info with account_id as foreign key. I used to save a new account like this:

account_info account = new account_info();
account.name = "blabla";
.....
acount_other_info accountOtherInfo = new acount_other_info();
accountOtherInfo.something = "blablabla";
......
account.acount_other_info = accountOtherInfo;

datacontext.account_infos.InsertOnSubmit(account);
datacontext.account_infos.SubmitChanges();

This code used to save both account_info and acount_other_info data in the db with the same account_id, but after updating to the latest version of devart dotconnect the code only saves account_info..

Does anyone have any clue?? Thank you!
Partalakos
 
Posts: 7
Joined: Wed 21 Jul 2010 17:34

Postby StanislavK » Wed 09 Mar 2011 12:52

Thank you for the report, we have reproduced and fixed the problem. The fix will be available in one of the nearest builds; we will post here when the corresponding build is released.

As a temporary workaround, you can call InsertOnSubmit for both 'master' and 'detail' entities.
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Postby Partalakos » Wed 09 Mar 2011 16:15

Well i search a lot and i found that the associations in the DataContext changed or updated (not sure how was before cause i never check it) to OneToOne.
I just change them to OneToMany from the properties and it work again but i am not sure if that is good. Its temporary works fine for me now.
I will wait for the new release to check it again.

PS. that change happened to 3 of 15 tables in database. all other tables was OneToMany, just let you know this.

Thanks for your help StanislavK.
Partalakos
 
Posts: 7
Joined: Wed 21 Jul 2010 17:34

Postby StanislavK » Fri 11 Mar 2011 17:55

We have released the new 2.20.15 build of LinqConnect (and the corresponding 6.10.121 build of dotConnect for MySQL) where this issue is fixed. The new builds can be downloaded from
http://www.devart.com/dotconnect/mysql/download.html
http://www.devart.com/linqconnect/download.html
(the trial version) or from Registered Users' Area (for users with active subscription only):
http://secure.devart.com/

For the detailed information about the fixes and improvements available in LinqConnect 2.20.15 and dotConnect for MySQL 6.10.121, please refer to
http://www.devart.com/forums/viewtopic.php?t=20478
http://www.devart.com/forums/viewtopic.php?t=20471
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Postby Partalakos » Wed 16 Mar 2011 02:20

well StanislavK i already install the new version and i think its ok now,i didn't finish the tests cause when was starting to test it i think that i found another one issue, i have 2 tables with 1 foreign key (ID)
I used to add something in the first table with 1 id, and was working fine until now. I check the queries with the DbMonitor and i see its success with the first Insert in db but it dosen't get the id of the item to insert the other info of that item in the second table.

One sample of the code i use is :

var asd = new FirstTable();
asd.FirstName = "Test1";
asd.LastName = "Test2";

var abc = new SecondTable();
abc.MiddleName = "Test3";

ads.SecondTable = adc;
Context.SubmitChanges();

The 2 items must have the same id...

That was working fine before i update to the latest version, now its not.
So i cant tell you for sure if its working :P

Thanks in Advance for your help.
George.
Partalakos
 
Posts: 7
Joined: Wed 21 Jul 2010 17:34

Postby StanislavK » Wed 16 Mar 2011 15:37

As far as I can understand, the above entities are connected with a one-to-one association. Am I correct? If yes, please specify the following:
- which of these entities is the parent one;
- where the entity key for both tables originates from (i.e., is it set manually in the code, or, maybe, generated by a trigger at the server?);
- what is the result of this operation (e.g., the first entity has Id equal to 10, and the second one has zero Id).

If possible, please send us a small complete project with which the issue can be reproduced.
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Postby Partalakos » Wed 16 Mar 2011 17:46

Hey StanislavK thanks for your quick reply. I send you a sample project with
2 of my DB tables inside a sub folder. You can import them to MySQL and you will see the problem your self.

which of these entities is the parent one;
--Account_Other_Info is the parent One.
where the entity key for both tables originates from (i.e., is it set manually in the code, or, maybe, generated by a trigger at the server?);
-- Manually from DB.
what is the result of this operation (e.g., the first entity has Id equal to 10, and the second one has zero Id).
-- If i understand that you are saying. in the first table the id is auto increase so it get the latest and the second one as i see from the DBMonitor has 0 for sure. (It must be equal with the auto Increase ID from the first table)

Please check it and let me know, Thanks again for your time and your help :)
George.
Partalakos
 
Posts: 7
Joined: Wed 21 Jul 2010 17:34

Postby StanislavK » Thu 17 Mar 2011 17:32

Thank you for your assistance, we've reproduced the problem. We will analyze it and inform you about the results as soon as possible.
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Postby StanislavK » Tue 19 Apr 2011 12:13

We have fixed the issue with inserting both 'parent' and 'child' entities connected with a one-to-one association in case the 'parent' entity has auto-generated Id. The fix is available in the new 6.10.141 version of dotConnect for MySQL (the corresponding version of LinqConnect is 2.20.21). The new build can be downloaded from
http://www.devart.com/dotconnect/mysql/download.html
(the trial version) or from Registered Users' Area (for users with active subscription only):
http://secure.devart.com/

For more information about the fixes and improvements available in dotConnect for MySQL 6.10.141, please refer to
http://www.devart.com/forums/viewtopic.php?t=20790
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Postby kruthi9999 » Fri 20 May 2011 14:25

plz anybody help me for my problem ie i have created c# window forms.i have created a table in my sql for one form. but i coudnt connect. plz any body give me step by step procedure.i have installed devart and added as referance . after connecting to data i want to retrieve it. am totally new to this
kruthi9999
 
Posts: 1
Joined: Thu 19 May 2011 11:04

Postby StanislavK » Fri 20 May 2011 15:50

There are several possible ways to retrieve data from the database with dotConnect for MySQL.

For example, you can use the general ADO.NET functionality, i.e., establish a connection and retrieve data, e.g., with the help of the MySqlCommand and MySqlDataReader classes. For the walkthroughs on these steps, please refer to the 'Getting Started' section of our documentation:
http://www.devart.com/dotconnect/mysql/docs/GettingStarted.html

Another way is to use one of ORM (object-relational mapping) solutions, e.g., LinqConnect. The LinqConnect tutorial is available at
http://www.devart.com/dotconnect/mysql/docs/Tutorial_LINQ.html

Feel free to contact us if anything is unclear.
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48


Return to dotConnect for MySQL