This is a migrated thread and some comments may be shown as answers.

Adding multiple records

2 Answers 67 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sean
Top achievements
Rank 2
Sean asked on 14 Jun 2010, 06:53 PM

Hi guys,

I have searched for a solution to this but have not yet seen anything that works.

I have a static table of tasks that must be completed for a newly submitted request ticket.
When the user submits his request, I grab the list, assosicte it with the request id and
populate a task completion table. However, i am getting cache errors from my object scope.

Here is the code block:

 
public void CreateTaskList(int requestid)  
        {  
            try 
            {  
                //Load the tasks from the static TASKS table  
                var tasks = Load();  
                 
                //Create a blank TASK COMPLETION record for each task and associate it with 
                //the request id 
 this will be updated as various reviewers complete their 
                //review of the request
                foreach (var task in tasks)  
                {  
                    var asset = new RmoTaskCompletion  
                    {  
                       RequestId = requestid,  
                       TaskId = task.TaskId,  
                       Date1 = DateTime.Now,  
                       Comments = "",  
                       Submitter = "",  
                       IsComplete = false,  
                       TaskDescription = task.TaskDescription  
                    };  
 
                    if(!_sc.Transaction.IsActive)  
                        _sc.Transaction.Begin();  
                    _sc.Add(asset);//Error is thrown here for the second record  
                    _sc.Transaction.Commit();  
                }  
            }  
            catch (Exception ex)  
            {  
                LogManager.LogError(ex);  
            }  
        } 

Thanks. I imagine it is fairly simple, but I can't seem to solve it.

Sean

2 Answers, 1 is accepted

Sort by
0
Serge
Telerik team
answered on 16 Jun 2010, 05:06 PM
Hello Sean ,

 I do not see anything wrong with your code so the exception should be coming from the surroundings, this being the object scope provider or the Load() method. 

Can you please provide information as to what kind of exception is thrown, how are you managing your scope's life cycle or any other thing about your code you think might help figure this out. It would be best if you could provide a demo project but it is not absolutely necessary. 

I am looking forward to resolving this issue.

Sincerely yours,
Serge
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sean
Top achievements
Rank 2
answered on 17 Jun 2010, 08:03 PM
Hi guys,

I solved my own issue. The table needed to have a key pair. When I first set it up, only RequestId was a key. Now, the RequestId and TaskId form a key pair. I manually added the change to the table as well as the OpenAccess app.config. However, it seems I had to use the tool to regenerate the class for it to work...

Anyway, the error was being thrown because I was trying to insert a record with a duplicate key (RequestId never changes for this loop, only the taskId). I never saw the duplicate key message, however, so it took me a while to realize my mistake.

Thanks!

Sean

Tags
Development (API, general questions)
Asked by
Sean
Top achievements
Rank 2
Answers by
Serge
Telerik team
Sean
Top achievements
Rank 2
Share this question
or