Answered Update all unique records (compare a field in 2 different tables)

onmyway

Member
Joined
Jan 18, 2016
Messages
12
Programming Experience
Beginner
Hi guys,

I hope you can help me.

I would like to update all Unique records by verifying that the Project Number of one table does not exist in the other.

Currently I have the procedure below, but I get an error as the returned results are more than 2100:

[h=2]The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Too many parameters were provided in this RPC request. The maximum is 2100.[/h]
Any ideas how I can rewrite this to work?

C#:
  public static void NewRecords()
        {
            using (var stageContext = new StagingTableDataContext())
            {
                using (var destinationContext = new DestinationTableDataContext())
                {
                    var allProjectNames = destinationContext.THEOPTIONs.Select(u => u.NAME).ToList(); 
                    var deltaList = stageContext.ProjectMasters.Where(u => !allProjectNames.Contains(u.Finance_Project_Number)).ToList();


                    deltaList.ForEach(u => u.Processing_Result = 0);
                    deltaList.ForEach(u => u.Processing_Result_Text = "UNIQUE");


                }
                stageContext.SubmitChanges();
            }
        }

Thank you in advance!
 
Herewith the solution - an added .ToList :D:
C#:
[COLOR=#00008B]public[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]static[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]void[/COLOR][COLOR=#000000] [/COLOR][COLOR=#2B91AF]NewRecords[/COLOR][COLOR=#000000]()[/COLOR][COLOR=#000000]
        [/COLOR][COLOR=#000000]{[/COLOR][COLOR=#000000]
            [/COLOR][COLOR=#00008B]using[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]([/COLOR][COLOR=#00008B]var[/COLOR][COLOR=#000000] stageContext [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]new[/COLOR][COLOR=#000000] [/COLOR][COLOR=#2B91AF]StagingTableDataContext[/COLOR][COLOR=#000000]())[/COLOR][COLOR=#000000]
            [/COLOR][COLOR=#000000]{[/COLOR][COLOR=#000000]
                [/COLOR][COLOR=#00008B]using[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]([/COLOR][COLOR=#00008B]var[/COLOR][COLOR=#000000] destinationContext [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]new[/COLOR][COLOR=#000000] [/COLOR][COLOR=#2B91AF]DestinationTableDataContext[/COLOR][COLOR=#000000]())[/COLOR][COLOR=#000000]
                [/COLOR][COLOR=#000000]{[/COLOR][COLOR=#000000]
                    [/COLOR][COLOR=#00008B]var[/COLOR][COLOR=#000000] allProjectNames [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] destinationContext[/COLOR][COLOR=#000000].[/COLOR][COLOR=#2B91AF]THEOPTIONs[/COLOR][COLOR=#000000].[/COLOR][COLOR=#2B91AF]Select[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]u [/COLOR][COLOR=#000000]=>[/COLOR][COLOR=#000000] u[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]NAME[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#2B91AF]ToList[/COLOR][COLOR=#000000]();[/COLOR][COLOR=#000000] 
                    [/COLOR][COLOR=#00008B]var[/COLOR][COLOR=#000000] deltaList [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] stageContext[/COLOR][COLOR=#000000].[/COLOR][COLOR=#2B91AF]ProjectMasters[/COLOR][COLOR=#000000].[/COLOR][COLOR=#2B91AF]ToList[/COLOR][COLOR=#000000]().[/COLOR][COLOR=#2B91AF]Where[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]u [/COLOR][COLOR=#000000]=>[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]![/COLOR][COLOR=#000000]allProjectNames[/COLOR][COLOR=#000000].[/COLOR][COLOR=#2B91AF]Contains[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]u[/COLOR][COLOR=#000000].[/COLOR][COLOR=#2B91AF]Finance_Project_Number[/COLOR][COLOR=#000000])).[/COLOR][COLOR=#2B91AF]ToList[/COLOR][COLOR=#000000]();[/COLOR][COLOR=#000000]

                    deltaList[/COLOR][COLOR=#000000].[/COLOR][COLOR=#2B91AF]ForEach[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]u [/COLOR][COLOR=#000000]=>[/COLOR][COLOR=#000000] u[/COLOR][COLOR=#000000].[/COLOR][COLOR=#2B91AF]Processing_Result[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]0[/COLOR][COLOR=#000000]);[/COLOR][COLOR=#000000]
                    deltaList[/COLOR][COLOR=#000000].[/COLOR][COLOR=#2B91AF]ForEach[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]u [/COLOR][COLOR=#000000]=>[/COLOR][COLOR=#000000] u[/COLOR][COLOR=#000000].[/COLOR][COLOR=#2B91AF]Processing_Result_Text[/COLOR][COLOR=#000000] [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]"UNIQUE"[/COLOR][COLOR=#000000]);[/COLOR][COLOR=#000000]

                [/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000]
                stageContext[/COLOR][COLOR=#000000].[/COLOR][COLOR=#2B91AF]SubmitChanges[/COLOR][COLOR=#000000]();[/COLOR][COLOR=#000000]
            [/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000]
        [/COLOR][COLOR=#000000]}[/COLOR]
 
Please Note: Unfortunately I cannot mark the post as SOLVED - I cannot access the prefix field in my main post. It does not appear - even in advance view.
 
Back
Top Bottom