Related table not pulling prefetch in all instances

Posts   
 
    
bvalle
User
Posts: 54
Joined: 07-Jun-2006
# Posted on: 02-Nov-2007 15:04:34   

Hello LLBLGen pro support

LLBLGen Pro 2002 - 2006 Version 2.0.0.0 Final Release February 14th, 2007

I have a piece of code that I pull records from a table DevicePointSchedule and I prefetch a required Device record with it, however once in a while one of the records does not get its Device record, even though it is not possible to have a DevicePoint without a Device record by SQL dependency. Is this possible? I mean was there a bug on the system? Or could I just be pushing the limits here? This function bellow is called a couple of hundred times a minute.


public static bool Get_DevicePointScheduleEC (int PSCHRecordsPerBlock,
                                                      out EntityCollection<DevicePointScheduleEntity> DPSEC)
        {
            bool RetVal = false;

            DateTime MaxProcessDateTime = DateTime.UtcNow.AddSeconds(5);

            //Create new DevicePointSchedule entity collection
            DPSEC = new EntityCollection<DevicePointScheduleEntity>();

                /// prefetch constructor
                PrefetchPath2 DPStoDD = new PrefetchPath2((int)EntityType.DevicePointScheduleEntity);
                DPStoDD.Add(DevicePointScheduleEntity.PrefetchPathDeviceData)
               .SubPath.Add(DeviceDataEntity.PrefetchPathChannel);

                //Create 'WhereClause' bucket to hold all the 'WhereClausePhrase' predicates
                RelationPredicateBucket WhereClause = new RelationPredicateBucket();

                //Create 'WhereClausePhrase' predicate
                IPredicateExpression WhereClausePhrase = new PredicateExpression();
                WhereClausePhrase.Add      (DevicePointScheduleFields.ProcessEnabled  == 1);
                WhereClausePhrase.AddWithAnd(DevicePointScheduleFields.ProcessDateTime <= MaxProcessDateTime);

                //Add 'WhereClausePhrase' predicate to the 'WhereClause' bucket
                WhereClause.PredicateExpression.Add(WhereClausePhrase);

                //Create empty sorting expression
                SortExpression SortExpr = new SortExpression();
                SortExpr.Add(DevicePointScheduleFields.ProcessDateTime | SortOperator.Ascending);

                //Create the data adapter to be used
                using (DataAccessAdapter DAA = new DataAccessAdapter())
                {
                    //Perform the fetch and prefetch
                    DAA.FetchEntityCollection(DPSEC, WhereClause, PSCHRecordsPerBlock, SortExpr, DPStoDD);

                    RetVal = true;
                }

                for (int count = 0; count < DPSEC.Count; count++ )
                {
                    /// checks if the DeviceData was really prefetched
                    if (DPSEC[count].DeviceData == null)
                    {

        //// I put a break point on the next line and it breaks one in a while and not
        //// on the first record, but sometimes it will pull 80 records and only one 
        //// will call this line.

                        RetVal = false;
                    }
                }
            
            return RetVal;
        }

Please not the comment close the the RetVal = false.

Am I making a simple mistake and just not seen it? If not do you think upgrading to the latest version of llblgen pro would fix my issue. What would cause this to happen?

Please let me know,

God bless, Bruno de França Valli

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 02-Nov-2007 16:09:27   

When the code breaks to the breakpoint, do you examine the database to make sure there is a Device for this DevicePoint, or even you may check the FK in the DevicePoint, if it has a vlue. FKs can have null values, if defined to allow nulls in the database.

                    if (DPSEC[count].DeviceData == null)
                    {
                        int deviceId = DPSEC[count].DeviceID;                   

                        RetVal = false;
                    }

Also it is recommended that you always use the latest release of the LLBLGen Pro version you are using.

bvalle
User
Posts: 54
Joined: 07-Jun-2006
# Posted on: 02-Nov-2007 20:34:09   

Yes, I did check the DeviceID and they do exist on the Device table, therefore I know the record is there, also if I run a query on the database doing a Join I do see the entry in there.

I will try to run the latest version of LLBLGen Pro and see if the problem goes away.

Thank you, BFV