Sunday, September 21, 2008 7:04 AMOk here is the situation:
I have a table in my DB called ytVideos, in this table are 3 columns, id (pri Key with auto inc) ytUserName, and ytVidId (this is set to unique key as well)
Problem is im getting XML data 50 entries at a time I am adding these to my linq Insertonsubmit(ytvideo) looping through all the entries. Then ill move on to the next page of entries again another 50. After i have looped through all the entries and pages i try to run dc.submitchanges() I get a exeption thrown saying that I can not insert duplicate records in the ytVidId column. What is happening is the datasupplier might give me id xyz123 as page 1 entry 50 and then on page 2 entry 52 (if you will) xyz123 again. When i try and submit it fails, I got it to work if i submit after every record but im trying to save resources on DB Calls. Is there a way to check the "pending" linq records for duplicates and remove the row before i fire submitchanges() ?????
Wednesday, September 24, 2008 6:39 AM
Since the “ytVidld” column should be unique, in my opinion, there are probably two approaches to overcome this duplicate records issue.
1. In the loop, after insert a record, we do submit changes immediately, if the exception raised and it says “duplicate record”, use try catch clause the wrap it and handle the exception, then do the next.
Wednesday, September 24, 2008 5:36 PMThanks for the reply. My whole goal was to prevent multiple calls to the data base since i was using linq. I have come up with a way that works, but not sure of the overhead that it will cost.. I create a listarray and everytime i add a submitonchange i add the id to that array then on the next loop i check if the value has been added to the arraylist if not i insert it seems to work. I also have linq query all records by a userId on page load to see if it exsits in the db already if it does i update insted of insert. Im think that i am ending up with only two calls to db one to get records on load and one to submit changes, is this correct.
Thursday, September 25, 2008 2:16 AM
Do not too much concerns about duplicate records, because the DBMS will help us to prevent this issue.
And I believe that submit changes only once for multiple records will be fine.