Changing DbFunctionCall return object-not-referenced of fetching collection

Posts   
 
    
robertpnl
User
Posts: 6
Joined: 31-Jul-2007
# Posted on: 08-Dec-2007 17:30:22   

Hi,

LLBLGen pro: version 2.5 Runtime lib: SD.LLBLGen.Pro.DQE.SqlServer.NET20 (2.5.0.0) and: SD.LLBLGen.Pro.ORMSupportClasses.NET20 (2.5.0.0) .Net 2.0, language C# Using generated code for Adapter.

The problem: During a loop, first call of FetchEntityCollection will works. But when the DbFunctionCall will be changed, the function FetchEntityCollection will report an object-not-referenced (all parameters are not null). For stack see below of this posting.

Enviroment: In a short loop, the FetchEntityCollection will be called with some parameters. One of the parameter is an 'IRelationPredicateBucket'. A FieldCompareValuePredicate is be add to this filter. This FieldCompareValuePredicate use a ResultSetField ('fiel') to generate a SUBSTRING query to check on some character within a string. Here you can see that we trying to check on a character position of field Track.strSunday.


IRelationPredicateBucket filter = new RelationPredicateBucket();

ResultsetFields fiel = new ResultsetFields(1);
fiel.DefineField(GetDbFieldofWeekDay(start.DayOfWeek), 0, "weekday");
DbFunctionCall dbcall = new DbFunctionCall("SUBSTRING({0}, " + strHour + ", 1)", new object[] { Track.strSunday });
fiel[0].ExpressionToApply = dbcall;

FieldCompareValuePredicate seldayweek = new FieldCompareValuePredicate(
      fiel[0], null, ComparisonOperator.Equal, "1");
filter.PredicateExpression.AddWithAnd(seldayweek);

Next line will work (da = DataAccessAdapter, 'sort' is some GUID for randoming, 'incl' will for selecting only some fields, but this on 'null' will not solved this problem):


da.FetchEntityCollection(_coll, filter, 1, sort, null, incl);

But then, when I changed this DbFunctionCall as follows, the next call of FetEntityCollection will thrown an exception:


dbcall.FunctionName = "SUBSTRING({0}, " + newhour + ", 1)";
dbcall.FunctionParameters = new object[] { Track.strMonday };

Changing the first line will not interrupt the loop (no throwing) and query is also be changed. But when changing the 'Functionparameters' with an another entityfield, this returns an exception on the function FetchEntityCollection object-not-referenced.


while (currenttime <= stop)
{
       // ...
       if (currenttime.DayOfWeek != currentdayofweek)
       {
                 // When another entityfield will be set, FetEntityCollection return an exception
                 dbcall.FunctionParameters = new object[] { GetEntityOfDayofWeek(currenttime.DayofWeek) };
            
        }

        da.FetchEntityCollection(_coll, filter, 1, sort, null, incl);
}

Another solutions what i've trying: - changing fiel.DefineField with new entity doesn't work (same error) - Creating new DbFunctionCall and set this on fiel[0] doesn't change the query

so, what is wrong? Maybe I doing thist on the wrong way? smile Thank you.


   at SD.LLBLGen.Pro.DQE.SqlServer.SqlServerSpecificCreator.CreateObjectName(IFieldPersistenceInfo persistenceInfo)
   at SD.LLBLGen.Pro.DQE.SqlServer.SqlServerSpecificCreator.CreateFieldName(IFieldPersistenceInfo persistenceInfo, String fieldName, String objectAlias, Boolean appendAlias, String containingObjectName, String actualContainingObjectName)
   at SD.LLBLGen.Pro.ORMSupportClasses.DbSpecificCreatorBase.ConvertFieldToRawName(IEntityFieldCore fieldCore, IFieldPersistenceInfo persistenceInfo, String fieldName, String objectAlias, Int32& uniqueMarker, Boolean applyAggregateFunction)
   at SD.LLBLGen.Pro.DQE.SqlServer.SqlServerSpecificCreator.CreateFieldName(IEntityFieldCore fieldCore, IFieldPersistenceInfo persistenceInfo, String fieldName, String objectAlias, Int32& uniqueMarker, Boolean applyAggregateFunction)
   at SD.LLBLGen.Pro.ORMSupportClasses.DbFunctionCall.CreateParameterFragments(Int32& uniqueMarker, Boolean inHavingClause)
   at SD.LLBLGen.Pro.ORMSupportClasses.DbFunctionCall.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause)
   at SD.LLBLGen.Pro.ORMSupportClasses.DbFunctionCall.SD.LLBLGen.Pro.ORMSupportClasses.IExpression.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause)
   at SD.LLBLGen.Pro.ORMSupportClasses.DbSpecificCreatorBase.ConvertFieldToRawName(IEntityFieldCore fieldCore, IFieldPersistenceInfo persistenceInfo, String fieldName, String objectAlias, Int32& uniqueMarker, Boolean applyAggregateFunction)
   at SD.LLBLGen.Pro.DQE.SqlServer.SqlServerSpecificCreator.CreateFieldName(IEntityFieldCore fieldCore, IFieldPersistenceInfo persistenceInfo, String fieldName, String objectAlias, Int32& uniqueMarker, Boolean applyAggregateFunction)
   at SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareValuePredicate.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause)
   at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause)
   at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause)
   at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker)
   at 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)
   at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause)
   at 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)
   at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateSelectDQ(IEntityFields2 fieldsToFetch, IFieldPersistenceInfo[] persistenceInfoObjects, IPredicateExpression filter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollectionInternal(IEntityCollection2 collectionToFill, IRelationPredicateBucket& filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields)
   at _TestApp.Program.Main(String[] args) in Program.cs:line 129
   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()

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 09-Dec-2007 20:29:23   

Could you please post the _GetEntityOfDayofWeek _function code snippet.

David Elizondo | LLBLGen Support Team