- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
Max Date Sub Query
Joined: 20-Sep-2007
I am pulling my hair out (what little I have left ) on this one. I am using LLBL ver. 2.0 with Self Servicing. I've done this same thing with adapter based code with no problem. But for some reason I am always getting "Object reference not set to an instance of an object." on the following:
Line 225: // perform the fetch combined with the projection. Line 226: TypedListDAO dao = new TypedListDAO(); Line 227: dao.GetAsProjection(valueProjectors, projector, null, fields, filter, relations, 0, null, true); Line 228: Line 229: return users[0];
When I replace the relations with null everything works fine. However when I add the relations back in I get the error.
When I inspect the relations I get the following which appears to be correct.
(
(
coreUserLogin INNER JOIN coreUser ON coreUserLogin.NUserLoginID=coreUser.NUserLoginID
)
LEFT JOIN coreUserAccessLogEntity ON coreUserEntity.NUserID=coreUserAccessLogEntity.NUserID AND
(
CoreUserAccessLogEntity.[DEntered] IN
(
SELECT MAX
(
LoginDate.[DEntered]
)
FROM CoreUserAccessLogEntity AS [LoginDate] WHERE
(
CoreUserAccessLogEntity.[NUserID] = LoginDate.[NUserID]
)
)
)
)
SOURCE CODE / STACK TRACE
IPredicateExpression filter = new PredicateExpression();
filter.Add(CoreUserFields.NClientID == clientId);
filter.AddWithAnd(CoreUserFields.NUserID == userId);
IRelationCollection relations = new RelationCollection();
relations.Add(CoreUserEntity.Relations.CoreUserLoginEntityUsingNUserLoginID);
relations.Add(CoreUserEntity.Relations.CoreUserAccessLogEntityUsingNUserID, JoinHint.Left);
IPredicateExpression subQueryFilters = new PredicateExpression();
subQueryFilters.Add(
new FieldCompareExpressionPredicate(
CoreUserAccessLogFields.NUserID, null,
ComparisonOperator.Equal,
new Expression(CoreUserAccessLogFields.NUserID.SetObjectAlias("LoginDate")))
);
IPredicateExpression maxFilter = new PredicateExpression();
maxFilter.Add(
new FieldCompareSetPredicate(
CoreUserAccessLogFields.DEntered, null,
CoreUserAccessLogFields.DEntered.SetAggregateFunction(AggregateFunction.Max).SetObjectAlias("LoginDate"), null,
SetOperator.In,
subQueryFilters));
IEntityRelation maxRelation = CoreUserEntity.Relations.CoreUserAccessLogEntityUsingNUserID;
maxRelation.CustomFilter = maxFilter;
relations.Add(maxRelation).HintForJoins = JoinHint.Left;
List<User.UserEntity> users = new List<LenderFlex.CalyxConnect.BusinessLogic.User.UserEntity>();
ResultsetFields fields = new ResultsetFields(5);
fields[0] = CoreUserFields.TFirstName;
fields[1] = CoreUserFields.TLastName;
fields[2] = CoreUserFields.TEmail;
fields[3] = CoreUserFields.NClientID;
fields[4] = CoreUserFields.NUserID;
//fields[5] = CoreUserAccessLogFields.DEntered;
DataProjectorToCustomClass<User.UserEntity> projector = new DataProjectorToCustomClass<User.UserEntity>(users);
// Define the projections of the fields.
List<IDataValueProjector> valueProjectors = new List<IDataValueProjector>();
valueProjectors.Add(new DataValueProjector("FirstName", 0, typeof(string)));
valueProjectors.Add(new DataValueProjector("LastName", 1, typeof(string)));
valueProjectors.Add(new DataValueProjector("Email", 2, typeof(string)));
valueProjectors.Add(new DataValueProjector("ClientId", 3, typeof(int)));
valueProjectors.Add(new DataValueProjector("UserId", 4, typeof(System.Nullable<System.Guid>)));
//valueProjectors.Add(new DataValueProjector("LastLogin", 5, typeof(DateTime)));
// perform the fetch combined with the projection.
TypedListDAO dao = new TypedListDAO();
dao.GetAsProjection(valueProjectors, projector, null, fields, filter, relations, 0, null, true);
[NullReferenceException: Object reference not set to an instance of an object.] SD.LLBLGen.Pro.DQE.SqlServer.SqlServerSpecificCreator.CreateObjectName(IFieldPersistenceInfo persistenceInfo) +48 SD.LLBLGen.Pro.DQE.SqlServer.SqlServerSpecificCreator.CreateFieldName(IFieldPersistenceInfo persistenceInfo, String fieldName, String objectAlias, Boolean appendAlias, String containingObjectName) +70 SD.LLBLGen.Pro.ORMSupportClasses.DbSpecificCreatorBase.ConvertFieldToRawName(IEntityFieldCore fieldCore, IFieldPersistenceInfo persistenceInfo, String fieldName, String objectAlias, Int32& uniqueMarker, Boolean applyAggregateFunction) +108 SD.LLBLGen.Pro.DQE.SqlServer.SqlServerSpecificCreator.CreateFieldName(IEntityFieldCore fieldCore, IFieldPersistenceInfo persistenceInfo, String fieldName, String objectAlias, Int32& uniqueMarker, Boolean applyAggregateFunction) +40 SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Boolean relationsSpecified, Boolean sortClausesSpecified) +445 SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause) +257 SD.LLBLGen.Pro.DQE.SqlServer.SqlServerSpecificCreator.CreateSubQuery(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldPersistenceInfos, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, IGroupByCollection groupByClause, Int32& uniqueMarker) +175 SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareSetPredicate.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause) +247 SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause) +447 SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause) +447 SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker) +6 SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Boolean relationsSpecified, Boolean sortClausesSpecified) +1999 SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause) +257 SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreatePagingSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) +125 SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.CreateQueryFromElements(ITransaction transactionToUse, IEntityFields fields, IPredicate filter, IRelationCollection relations, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupByClause, Boolean allowDuplicates, Int32 pageNumber, Int32 pageSize) +469 SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetAsProjection(List
1 valueProjectors, IGeneralDataProjector projector, ITransaction transactionToUse, IEntityFields fields, IPredicateExpression filter, IRelationCollection relations, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupByClause, Boolean allowDuplicates, Int32 pageNumber, Int32 pageSize) +61 SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetAsProjection(List
1 valueProjectors, IGeneralDataProjector projector, ITransaction transactionToUse, IEntityFields fields, IPredicateExpression filter, IRelationCollection relations, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates) +40 LenderFlex.CalyxConnect.BusinessLogic.Managers.DataManager.FetchUserById(Guid userId, Int32 clientId) in C:\Projects\LenderFlex.CalyxConnect\LenderFlex.CalyxConnect.BusinessLogic\Managers\DataManager.cs:227 LenderFlex.CalyxConnect.Admin.User.Bind() in C:\Projects\LenderFlex.CalyxConnect\LenderFlex.CalyxConnect\Admin\User.aspx.cs:32 LenderFlex.CalyxConnect.Admin.User.Page_Load(Object sender, EventArgs e) in C:\Projects\LenderFlex.CalyxConnect\LenderFlex.CalyxConnect\Admin\User.aspx.cs:22 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +47 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
Runtime v2.0.50727
That's not a correct runtime library version/build number.
Please check the following guidelines thread, for more details about how to get the correct runtime library version number: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7725
The File version is listed as 2.0.7.424 in the properties window.
Would you please try using the latest available version? Some issues were solved since the version you have.
Any help you can give today would be greatly appreciated
I'm sorry your reply didn't catch me.
Am I right in concluding that running the following code instead of the GetAsProjection() call will give the same exception:
DataTable dynamicList = new DataTable();
TypedListDAO dao = new TypedListDAO();
dao.GetMultiAsDataTable(fields, dynamicList, 0, null, filter, relations, true, null, null, 0, 0);
Joined: 20-Sep-2007
Walaa wrote:
The File version is listed as 2.0.7.424 in the properties window.
Would you please try using the latest available version? Some issues were solved since the version you have.
Do I need to upgrade to v2.5? I not sure which version as I thought I had the latest version of v2.0.
Thanks,
Joined: 20-Sep-2007
I upgraded to the demo version of 2.5 to see if that would fix any issues. I am still getting an error albeit a different one. Same code as before. Runtime version of 2.5.7.924
Index was outside the bounds of the array. 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.IndexOutOfRangeException: Index was outside the bounds of the array.
Line 214: // perform the fetch combined with the projection. Line 215: TypedListDAO dao = new TypedListDAO(); Line 216: dao.GetAsProjection(valueProjectors, projector, null, fields, filter, relations, 0, null, true); Line 217: Line 218: //DataTable dynamicList = new DataTable();
[IndexOutOfRangeException: Index was outside the bounds of the array.] SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Boolean relationsSpecified, Boolean sortClausesSpecified) +2326 SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause) +808 SD.LLBLGen.Pro.DQE.SqlServer.SqlServerSpecificCreator.CreateSubQuery(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldPersistenceInfos, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, IGroupByCollection groupByClause, Int32& uniqueMarker) +209 SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareSetPredicate.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause) +366 SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause) +579 SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause) +579 SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker) +31 SD.LLBLGen.Pro.ORMSupportClasses.RelationCollection.ToQueryText(Int32& uniqueMarker) +3452 SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Boolean relationsSpecified, Boolean sortClausesSpecified) +2060 SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause) +808 SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreatePagingSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) +183 SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFields selectList, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) +99 SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.CreateQueryFromElements(ITransaction transactionToUse, IEntityFields fields, IPredicate filter, IRelationCollection relations, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupByClause, Boolean allowDuplicates, Int32 pageNumber, Int32 pageSize) +909 SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetAsProjection(List
1 valueProjectors, IGeneralDataProjector projector, ITransaction transactionToUse, IEntityFields fields, IPredicateExpression filter, IRelationCollection relations, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupByClause, Boolean allowDuplicates, Int32 pageNumber, Int32 pageSize) +83 SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetAsProjection(List
1 valueProjectors, IGeneralDataProjector projector, ITransaction transactionToUse, IEntityFields fields, IPredicateExpression filter, IRelationCollection relations, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates) +64 LenderFlex.CalyxConnect.BusinessLogic.Managers.DataManager.FetchUserById(Guid userId, Int32 clientId) in C:\Projects\LenderFlex.CalyxConnect\LenderFlex.CalyxConnect.BusinessLogic\Managers\DataManager.cs:216 LenderFlex.CalyxConnect.Admin.User.Bind() in C:\Projects\LenderFlex.CalyxConnect\LenderFlex.CalyxConnect\Admin\User.aspx.cs:32 LenderFlex.CalyxConnect.Admin.User.Page_Load(Object sender, EventArgs e) in C:\Projects\LenderFlex.CalyxConnect\LenderFlex.CalyxConnect\Admin\User.aspx.cs:22 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +47 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
The problem occurs inside the field name creation where the persistence info is apparently unknown. As you're using selfservicing, the persistence info is already in the field, so there's something odd going on. As the exception occurs inside the subquery creation, it lead to this codesnippet:
IPredicateExpression maxFilter = new PredicateExpression();
maxFilter.Add(
new FieldCompareSetPredicate(
CoreUserAccessLogFields.DEntered, null,
CoreUserAccessLogFields.DEntered.SetAggregateFunction(AggregateFunction.Max).SetObjectAlias("LoginDate"), null,
SetOperator.In,
subQueryFilters));
in your initial post.
You use the ADAPTER ctor for this, not the selfservicing CTor.
Please rephrase this to:
IPredicateExpression maxFilter = new PredicateExpression();
maxFilter.Add(
new FieldCompareSetPredicate(
CoreUserAccessLogFields.DEntered,
CoreUserAccessLogFields.DEntered.SetAggregateFunction(AggregateFunction.Max).SetObjectAlias("LoginDate"),
SetOperator.In,
subQueryFilters));
An EntityField also implements IEntityFieldCore, but if you use the adapter CTor, the persistence info is passed as null initially, but is filled in later. As you're using selfservicing, no persistence info is filled in later, as it's assumed it's already in the field, hence the error.
Joined: 20-Sep-2007
I also had to rephrase the following to remove the null after IEntityField
IPredicateExpression subQueryFilters = new PredicateExpression();
subQueryFilters.Add(
new FieldCompareExpressionPredicate(
CoreUserAccessLogFields.NUserID, null
ComparisonOperator.Equal,
new Expression(CoreUserAccessLogFields.NUserID.SetObjectAlias("LoginDate")))
);
Worked like a charm after that. Thanks Walaa and Otis.