I have a list of values that I am looping through, determining whether each item exists in database table and then either updating or creating new row. Each time I use dataconext.submitchanges. I also need the ID for the newly created row which i get after submitchanges. Is there a better wa to do this than to connect on each cycle?
A:
dont SubmitChanges for each record (iteration of the loop). make changes to the collections from your datacontext and SubmitChanges at the end. LINQ will look after the initial querying and the submitting at the end. you're concurrency might be a problem but ignore that for now. likely, its not a concern unless ur iterating 1000's of records.
cottsak
2009-01-18 08:36:39