Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Run time error: "An item with the same key has already been added"
 

Pages: 1
LLBLGen Pro Runtime Framework
Run time error: "An item with the same key has already been added"
Page:1/1 

  Print all messages in this thread  
Poster Message
omar
User



Location:
Salmiya, Kuwait
Joined on:
15-Oct-2004 15:44:57
Posted:
569 posts
# Posted on: 26-Jan-2009 23:18:26.  
This is my current code setup
The SQL code I am trying to port to LINQ is

Code:
INSERT INTO @PFCollateral
SELECT a.PortfolioId,b.SecurityCode,Sum(b.Quantity)         
    ColQuantity,0,0,0,0,b.RestrictionType,b.SecurityType
FROM portfoliostrategy a
INNER join SecurityCollateral b ON a.TrxNo = b.TrxNo
WHERE b.ResDate<= @AsOfDate AND a.PortfolioId >= @FromPF and a.PortfolioId <= @ToPF
GROUP BY a.PortfolioId, b.SecurityCode, b.RestrictionType, b.SecurityType


The LINQ query I wrote is as follows:

Code:
var PFCollateral = (from a in metaData.PortfolioStrategy
                                     from b in metaData.SecurityCollateral
                                     where
                                         a.TrxNo == b.TrxNo &&
                                         b.ResDate <= new DateTime(2008 / 1 / 1) &&
                                         a.PortfolioNo >= 1 &&
                                         a.PortfolioNo <= 1
                                     group b by new
                                     {
                                        
                                         b.SecurityCode,
                                         b.RestrictionType,
                                         b.SecurityType,
                                            a.PortfolioNo
                                     } into g
                                     select new
                                     {
                                         PortfolioID = g.Key.PortfolioNo ,
                                         SecurityCode = g.Key.SecurityCode,
                                         ColQuantity = g.Sum(p => p.Quantity),
                                         Column1 = 0,
                                         Column2 = 0,
                                         Column3 = 0,
                                         Column4 = 0,
                                         RestrictionType = g.Key.RestrictionType ,
                                         SecurityType = g.Key.SecurityType
                                     });
                    MessageBox.Show(PFCollateral.Count().ToString());

At run time I get the following error

Code:
Message =An item with the same key has already been added.
Stack Trace =
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionClasses.ProjectionListExpression.AddElement(String name, Object element, Type elementType, Int32 elementIndex)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionClasses.ProjectionListExpression.AddExpressionElement(String elementName, Type elementType, Expression elementToAdd, Int32 elementIndex, IElementCreatorCore generatedCodeCreator, ITemplateGroupSpecificCreator frameworkElementCreator, MappingTracker trackedMappings, FunctionMappingsContainer functionMappings)
at SD.LLBLGen.Pro.LinqSupportClasses.LinqUtils.CoerceLinqExpressionToProjectionListExpression(Expression toCoerce, IElementCreatorCore generatedCodeElementCreator, ITemplateGroupSpecificCreator frameworkElementCreator, MappingTracker trackedMappings, FunctionMappingsContainer functionMappings)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleProjectionExpression(ProjectionExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle, SelectExpression newInstance)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleSelectExpression(SelectExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleAggregateExpression(AggregateExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.HandleExpressionTree(Expression expression)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.Execute(Expression expression)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
at BNIS.AMS.WIN.PostCashDeposite.Form1.TestLinq() in C:\AMS\BNIS.AMS.WIN.PostCashDeposite\Form1.cs:line 745
at BNIS.AMS.WIN.PostCashDeposite.Form1.Form1_Load(Object sender, EventArgs e) in C:\AMS\BNIS.AMS.WIN.PostCashDeposite\Form1.cs:line 139
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at BNIS.AMS.WIN.PostCashDeposite.Program.Main() in C:\AMS\BNIS.AMS.WIN.PostCashDeposite\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Now I managed to solve this by changing the LINQ query select projection to be

                                         Column1 = (g.Key.PortfolioID - g.Key.PortfolioID),
                                         Column2 = (g.Key.PortfolioID - g.Key.PortfolioID),
                                         Column3 = (g.Key.PortfolioID - g.Key.PortfolioID),
                                         Column4 = (g.Key.PortfolioID - g.Key.PortfolioID),

I dont understand why this is happening ???

We don't know who we are until we see what we can do  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8098 posts
# Posted on: 27-Jan-2009 07:05:45.  
Hi omar,

This looks like a bug fixed time ago. Could you please update to the latest runtime library version?


David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
mohamed
User



Location:
Salmia, kuwait
Joined on:
10-Mar-2008 19:55:21
Posted:
136 posts
# Posted on: 29-Jan-2009 23:17:30.  
Hi daelmo

I have worked with Omar on this problem and this is what happened

I think the reason of exception does not belongs to runtime library version(by testing in version 1-21-2009)

the reason is in static values
Code:

                                         Column1 = 0,
                                         Column2 = 0,
                                         Column3 = 0,
                                         Column4 = 0,



i changed value with 0,1,2,3 and its worked !!!! Shocked
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37796 posts
# Posted on: 30-Jan-2009 09:49:45.  
uhoh Embarrassed

It will be fixed today.


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37796 posts
# Posted on: 30-Jan-2009 13:51:25.  
Fixed.

See attached dll. It also fixes your other problem with the groupby.
Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.