- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
An item with the same key has already been added.
Joined: 14-May-2007
Hi,
Using 2.6 10 April 2008 build and the following Linq query:
var members = from u in metaData.Users
join ui in metaData.UserInterests on u.Id equals ui.UserId into uis
join ue in metaData.UserEducation on u.Id equals ue.UserId into ues
join ur in metaData.UserResidences on u.Id equals ur.UserId into urs
from uis2 in uis.DefaultIfEmpty()
from ues2 in ues.DefaultIfEmpty()
from urs2 in urs.DefaultIfEmpty()
orderby u.LastName, u.FirstName, u.Id
select new { u.Id, u.FirstName, u.LastName, uis2.Hobbies, uis2.Likes, uis2.Dislikes, ues2.SchoolName };
As soon as the "ur" join is added the statement fails with:
An item with the same key has already been added.
The Stacktrace is below. If I remove the 3rd join ("ur"), then the statement works.
I'm hacking around with Linq so my apologies of the query isn't right.
Thanks,
Shawn
ArgumentException: An item with the same key has already been added.]
System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +48
System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) +2668392
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionClasses.ProjectionListExpression.AddElement(String name, Object element, Type elementType, Int32 elementIndex) +431
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionClasses.ProjectionListExpression.AddEntityFieldsToProjectionList( EntityExpression expressionToHandle, IElementCreatorCore creator) +218
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionClasses.ProjectionListExpression.AddExpressionElement(String elementName, Type elementType, Expression elementToAdd, Int32 elementIndex, IElementCreatorCore generatedCodeCreator, ITemplateGroupSpecificCreator frameworkElementCreator, MappingTracker trackedMappings, FunctionMappingsContainer functionMappings) +1021
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder. CoerceLinqExpressionToProjectionListExpression(Expression toCoerce) +264
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder. HandleProjectionExpression(ProjectionExpression expressionToHandle) +202
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle) +1154
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle) +74
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleJoinExpression(JoinExpression expressionToHandle) +2342
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle) +837
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle) +74
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle, SelectExpression newInstance) +24
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle) +140
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleSelectExpression(SelectExpression expressionToHandle) +169
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleSortClauseExpression( SortClauseExpression expressionToHandle) +200
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle) +1289
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle) +74
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle, SelectExpression newInstance) +24
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle) +140
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleSelectExpression(SelectExpression expressionToHandle) +169
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleSortClauseExpression( SortClauseExpression expressionToHandle) +200
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle) +1289
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle) +74
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle, SelectExpression newInstance) +24
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle) +140
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleSelectExpression(SelectExpression expressionToHandle) +169
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleSortClauseExpression( SortClauseExpression expressionToHandle) +200
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle) +1289
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle) +74
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle, SelectExpression newInstance) +24
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle) +140
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleSelectExpression(SelectExpression expressionToHandle) +169
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle) +1245
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle) +74
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.HandleExpressionTree(Expression expression) +853
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.Execute(Expression expression) +10
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression) +4
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery
1.System.Collections.IEnumerable.GetEnumerator() +13
System.Web.UI.WebControls.PagedDataSource.GetEnumerator() +171
System.Web.UI.WebControls.GridView.CreateAutoGeneratedColumns(PagedDataSource dataSource) +296
System.Web.UI.WebControls.GridView.CreateColumns(PagedDataSource dataSource, Boolean useDataSource) +499
System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +970
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +59
System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +11
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +111
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +29
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
System.Web.UI.WebControls.GridView.DataBind() +4
_Default.Page_Load(Object sender, EventArgs e) in c:\Testing\VStudio2008\Projects\LLBLGenTesting\LinqTesting\WebSite\Default.aspx.cs:62
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436
Without more info we can't help you. PLease provide information about the entities, their relations with others, what database you're using etc. The readme states:
As this is beta code, it might be that it crashes. We did extensive testing on it, but as the code is very complex it might be we've overlooked some possible scenario's etc. The list below is ESSENTIAL to follow. If you don't obey this list, we can't help you and therefore won't help you. This is bad for you and for us, because we then might not fix a bug and you're not able to proceed. So please obey this list.
Linq is an abstraction layer above the LLBLGen Pro query API, so it means it's harder to track down errors. To be able to track down errors, before you post a question, please: - make SURE you're using the latest beta build - enable tracing of the DQE through the config file and obtain the generated query. - if you run into a crash, always obtain the FULL stacktrace. - always provide the full query in linq code - always provide information about inheritance structures of ALL entities involved in the query - always provide DDL SQL for the tables involved.
(we need this info to rebuild the query as you have it so we can be sure that if it runs here it is fixed, and to know for sure we have the correct reprocase)
Joined: 14-May-2007
Hi,
Thanks - I created a small test project to duplicate the issue...
Otis wrote:
- make SURE you're using the latest beta build
Using the 10 april 2008 build.
Otis wrote:
- enable tracing of the DQE through the config file and obtain the generated query.
Trace was enabled but file is empty.
Otis wrote:
- if you run into a crash, always obtain the FULL stacktrace.
[ArgumentException: An item with the same key has already been added.]
System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +48
System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +2668392
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionClasses.ProjectionListExpression.AddElement(String name, Object element, Type elementType, Int32 elementIndex) +431
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionClasses.ProjectionListExpression.AddEntityFieldsToProjectionList(EntityExpression expressionToHandle, IElementCreatorCore creator) +218
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionClasses.ProjectionListExpression.AddExpressionElement(String elementName, Type elementType, Expression elementToAdd, Int32 elementIndex, IElementCreatorCore generatedCodeCreator, ITemplateGroupSpecificCreator frameworkElementCreator, MappingTracker trackedMappings, FunctionMappingsContainer functionMappings) +1021
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.CoerceLinqExpressionToProjectionListExpression(Expression toCoerce) +264
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleProjectionExpression(ProjectionExpression expressionToHandle) +201
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle) +1154
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle) +74
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleJoinExpression(JoinExpression expressionToHandle) +2342
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle) +837
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle) +74
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleAndProcessJoinExpressionSide(SetExpression side, Expression sideSelector, Expression& handledSide, Expression& handledSideSelector, String& aliasSide) +22
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleJoinExpression(JoinExpression expressionToHandle) +486
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle) +837
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle) +74
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.HandleExpressionTree(Expression expression) +853
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.Execute(Expression expression) +10
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression) +4
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.System.Collections.IEnumerable.GetEnumerator() +13
System.Web.UI.WebControls.PagedDataSource.GetEnumerator() +171
System.Web.UI.WebControls.DataGrid.CreateAutoGeneratedColumns(PagedDataSource dataSource) +254
System.Web.UI.WebControls.DataGrid.CreateColumnSet(PagedDataSource dataSource, Boolean useDataSource) +1629786
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource) +295
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +56
System.Web.UI.WebControls.BaseDataList.DataBind() +52
_Default.Page_Load(Object sender, EventArgs e) in c:\Testing\VStudio2008\Projects\LLBLGenTesting\LinqTesting2\WebSite\Default.aspx.cs:84
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436
Otis wrote:
- always provide the full query in linq code
var testItems = from m in metaData.MasterTable
join c1 in metaData.ChildTable1 on m.Id equals c1.MasterId
join c2 in metaData.ChildTable2 on m.Id equals c2.MasterId
join c3 in metaData.ChildTable3 on m.Id equals c3.MasterId
select new { m.Id, m.Field1, c1Field1 = c1.Field1, c2field1 = c2.Field1, c3field1 = c3.Field1 };
Otis wrote:
- always provide information about inheritance structures of ALL entities involved in the query
No additional inheritance / sub-types created. Table hierarchy of sample includes 1 MasterTable, and 3 child tables (ChildTable1, ChildTable2, ChildTable3). LGP file for project should be attached.
Otis wrote:
- always provide DDL SQL for the tables involved.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MasterTable]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[MasterTable](
[Id] [uniqueidentifier] NOT NULL CONSTRAINT [DF_MasterTable_Id] DEFAULT (newid()),
[Field1] [nvarchar](255) NULL,
CONSTRAINT [PK_MasterTable] PRIMARY KEY CLUSTERED
(
[Id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ChildTable1]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[ChildTable1](
[Id] [uniqueidentifier] NOT NULL CONSTRAINT [DF_ChildTable1_Id] DEFAULT (newid()),
[Master_Id] [uniqueidentifier] NULL,
[Field1] [nvarchar](255) NULL,
CONSTRAINT [PK_ChildTable1] PRIMARY KEY CLUSTERED
(
[Id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ChildTable2]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[ChildTable2](
[Id] [uniqueidentifier] NOT NULL CONSTRAINT [DF_ChildTable2_Id] DEFAULT (newid()),
[Master_ID] [uniqueidentifier] NULL,
[Field1] [nvarchar](255) NULL,
CONSTRAINT [PK_ChildTable2] PRIMARY KEY CLUSTERED
(
[Id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[ChildTable3]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[ChildTable3](
[Id] [uniqueidentifier] NOT NULL CONSTRAINT [DF_ChildTable3_Id] DEFAULT (newid()),
[Master_Id] [uniqueidentifier] NULL,
[Field1] [nchar](10) NULL,
CONSTRAINT [PK_ChildTable3] PRIMARY KEY CLUSTERED
(
[Id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
Otis wrote:
(we need this info to rebuild the query as you have it so we can be sure that if it runs here it is fixed, and to know for sure we have the correct reprocase)
Understand - sorry for missing this previously.
Thanks again,
Shawn
Filename | File size | Added on | Approval |
---|---|---|---|
LinqTesting.lgp | 27,375 | 15-Apr-2008 19:22.02 | Approved |
Joined: 14-May-2007
Further to my previous post, I attempted with sample project to use Outer Joins vs Inner Join and am now getting "onClause can't be null <br >Parameter name: onClause.
Linq Query:
var testItems = from m in metaData.MasterTable
join c1 in metaData.ChildTable1 on m.Id equals c1.MasterId into c1_1
join c2 in metaData.ChildTable2 on m.Id equals c2.MasterId into c2_1
join c3 in metaData.ChildTable3 on m.Id equals c3.MasterId into c3_1
from c1_2 in c1_1.DefaultIfEmpty()
from c2_2 in c2_1.DefaultIfEmpty()
from c3_2 in c3_1.DefaultIfEmpty()
select new { m.Id, m.Field1, c1Field1 = c1_2.Field1, c2field1 = c2_2.Field1, c3field1 = c3_2.Field1 };
Stacktrace:
onClause can't be null
Parameter name: onClause
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: onClause can't be null
Parameter name: onClause
Source Error:
Line 65: public DynamicRelation(EntityType leftOperand, JoinHint joinType, EntityType rightOperand, string aliasLeftOperand, string aliasRightOperand, IPredicate onClause)
Line 66: {
Line 67: base.InitClass(joinType, aliasLeftOperand, aliasRightOperand, onClause, GeneralEntityFactory.Create(leftOperand), GeneralEntityFactory.Create(rightOperand));
Line 68: }
Line 69:
Source File: C:\Testing\VStudio2008\Projects\LLBLGenTesting\LinqTesting2\ClassLibs\DatabaseGeneric\RelationClasses\DynamicRelation.cs Line: 67
Stack Trace:
[ArgumentNullException: onClause can't be null
Parameter name: onClause]
SD.LLBLGen.Pro.ORMSupportClasses.DynamicRelationBase.InitClass(JoinHint joinType, String aliasLeftOperand, String aliasRightOperand, IPredicate onClause, Object leftOperand, Object rightOperand) +298
LinqTesting.RelationClasses.DynamicRelation..ctor(EntityType leftOperand, JoinHint joinType, EntityType rightOperand, String aliasLeftOperand, String aliasRightOperand, IPredicate onClause) in C:\Testing\VStudio2008\Projects\LLBLGenTesting\LinqTesting2\ClassLibs\DatabaseGeneric\RelationClasses\DynamicRelation.cs:67
LinqTesting.Linq.ElementCreator.CreateDynamicRelation(String leftOperandEntityName, JoinHint joinType, String rightOperandEntityName, String aliasLeftOperand, String aliasRightOperand, IPredicate onClause) in C:\Testing\VStudio2008\Projects\LLBLGenTesting\LinqTesting2\ClassLibs\DatabaseGeneric\Linq\LinqMetaData.cs:194
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.CreateDynamicRelation(Object left, Object right, JoinHint joinType, String aliasLeft, String aliasRight, IPredicate onClause) +420
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleJoinExpression(JoinExpression expressionToHandle) +1218
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle) +837
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle) +74
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleAndProcessJoinExpressionSide(SetExpression side, Expression sideSelector, Expression& handledSide, Expression& handledSideSelector, String& aliasSide) +22
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleJoinExpression(JoinExpression expressionToHandle) +486
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle) +837
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle) +74
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleAndProcessJoinExpressionSide(SetExpression side, Expression sideSelector, Expression& handledSide, Expression& handledSideSelector, String& aliasSide) +22
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleJoinExpression(JoinExpression expressionToHandle) +486
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle) +837
SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle) +74
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.HandleExpressionTree(Expression expression) +853
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.Execute(Expression expression) +10
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression) +4
SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.System.Collections.IEnumerable.GetEnumerator() +13
System.Web.UI.WebControls.PagedDataSource.GetEnumerator() +171
System.Web.UI.WebControls.DataGrid.CreateAutoGeneratedColumns(PagedDataSource dataSource) +254
System.Web.UI.WebControls.DataGrid.CreateColumnSet(PagedDataSource dataSource, Boolean useDataSource) +1629786
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource) +295
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +56
System.Web.UI.WebControls.BaseDataList.DataBind() +52
_Default.Page_Load(Object sender, EventArgs e) in c:\Testing\VStudio2008\Projects\LLBLGenTesting\LinqTesting2\WebSite\Default.aspx.cs:84
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436
I'm admittedly very, very new to Linq so....I hope this isn't a goose chase
Thanks,
Shawn
Joined: 14-May-2007
Couldn't help myself...here's a fix for the duplicate key error that seems to be working for me:
File: ProjectionLinkExpression.cs Line: 129
Replaced code if (addElement)... with:
if(addElement)
{
// different field, cook up new name (but make sure new name isn't already in use...)
nameToUse += _uniqueNameCounter.ToString();
for (int iTmp = 0; iTmp < this.Elements.Count; iTmp++)
{
if (this.ElementsPerName.ContainsKey(nameToUse))
{
_uniqueNameCounter++;
nameToUse += _uniqueNameCounter.ToString();
}
}
_uniqueNameCounter++;
}
Thanks,
Shawn
Joined: 14-May-2007
For the null onClause, I think it's happening because the join fields are different types of Guids...
MasterTable.Id is Guid ChildTable1.Master_Id is Guid?
In QueryExpressionBuilder.cs, this ends up creating a LeftSelector of type Convert. Below is output from the command window at a breakpoint set in QueryExpressionBuilder.cs / Line 2242.
>? relatedGroupJoin.LeftSelector
{Convert([508])}
[System.Linq.Expressions.UnaryExpression]: {Convert([508])}
NodeType: Convert
Type: {Name = "Nullable`1" FullName = "System.Nullable`1[[System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"}
>
This type falls through the switch in CreateOnClausePredicate...
Thanks, hope this helps a little. I'm just digging around to learn more about things.
Shawn
Thanks for the effort!
I could reproduce the first issue with northwind:
var q = from e in metaData.Employee
join e2 in metaData.Employee on e.EmployeeId equals e2.ReportsTo
join o in metaData.Order on e.EmployeeId equals o.EmployeeId
join et in metaData.EmployeeTerritory on e.EmployeeId equals et.EmployeeId
select new { e.LastName, e.EmployeeId, Manager = e2.LastName, o.OrderId, et.TerritoryId };
so I can add a unittest to the pack for it. I'll now see if your fix has any impact on the rest of the code.
It's caused by the fact that there are several projections (each join has a projection, which is handled but in the end not used, but that's unknown at that point) and a projection is merged into another, which has its uniquecounter set to 0 initially. In this case the ID shows up multiple times and it twice gets the value Id0.
A slightly more efficient patch:
// different field, cook up new name
string tmpNewName = string.Empty;
do
{
tmpNewName = nameToUse += _uniqueNameCounter.ToString();
_uniqueNameCounter++;
}
while(this.ElementsPerName.ContainsKey(tmpNewName));
nameToUse = tmpNewName;
I'll now look into your guid issue.
That issue is caused by the CreateOnClausePredicate routine which is a little retarded.
Say you do this:
var q = from c in metaData.Customer
join e in metaData.Employee on c.CustomerId[0] equals e.LastName[0]
select new { c.CustomerId, e.EmployeeId, e.LastName };
You get the same error, as it doesn't anticipate that it can expect a db function call wrapped inside an llblexpression.
The 'Convert' can be stripped off in general, though not always: nullability converts can be stripped off in many cases, the converts between types can't. I'll make sure this works properly (I can repro the issue with convert as well:
var q = from e in metaData.Employee
join e2 in metaData.Employee on e.EmployeeId equals e2.ReportsTo into j1
join o in metaData.Order on e.EmployeeId equals o.EmployeeId into j2
join et in metaData.EmployeeTerritory on e.EmployeeId equals et.EmployeeId into j3
from x1 in j1.DefaultIfEmpty()
from x2 in j2.DefaultIfEmpty()
from x3 in j3.DefaultIfEmpty()
select new { e.LastName, e.EmployeeId, Manager = x1.LastName, x2.OrderId, x3.TerritoryId };
Fixed in next build. To quick fix it, strip off the converts in the OnClause creation routine (using handledLeftSelector = RemoveConvertExpressionWrappers(handledLeftSelector); handledRightSelector = RemoveConvertExpressionWrappers(handledRightSelector);
at line 2205, before the if)
Any convert left at that stage is a null type convert, which can be ignored at that point in the tree.
I've added a more clever CreateOnClausePredicate routine, which can handle llblgen pro expressions (db function calls etc.) and constants as well.