Error with GetScaler

Posts   
 
    
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 22-Nov-2008 21:18:53   

Hi,

I'm getting a 'System.NullReferenceException' when I run the following code...


public int GetGuestID(int accountID, int ordinal)
        {
            DataAccessAdapter adapter = new DataAccessAdapter();

            ResultsetFields fields = new ResultsetFields(1);
            fields.DefineField(GuestFields.ContactId, 0, "ContactId");

            IPredicateExpression expression = new PredicateExpression();
            expression.Add(GuestFields.AccountId == accountID);
            expression.AddWithAnd(GuestFields.Ordinal == ordinal);

            return (int) adapter.GetScalar(fields, expression, null);
        }

Here's the stack trace. This code used to work. I think its only since I upgraded to 2.6 that its broken.

  at SD.LLBLGen.Pro.ORMSupportClasses.PersistenceCore. AddInheritanceRelatedElementsToQueryElementsForDynamicList(InheritanceHierarchyType hierarchyType, IList fields, IPredicateExpression filter, IRelationCollection relations, IInheritanceInfoProvider infoProvider, String forEntityName)

at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.GetScalar(IEntityFields2 fields, IPredicate filter, IGroupByCollection groupByClause, IRelationCollection relations) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.GetScalar(IEntityFields2 fields, IPredicate filter, IGroupByCollection groupByClause) at JGSR.BFWeekender.BusinessServices.AccountController.GetGuestID(Int32 accountID, Int32 ordinal) in G:\My Stuff\Development\Source\JGSREvents\Projects\Websites\BangfaceWeekender\JGSR.BFWeekender.BusinessServices\AccountController.cs:line 138 at JGSR.BFWeekender.Web.group.raver.btnSubmit_OnClick(Object sender, EventArgs e) in G:\My Stuff\Development\Source\JGSREvents\Projects\Websites\BangfaceWeekender\JGSR.BFWeekender.Web\group\raver.aspx.cs:line 91

Any ideas?

Cheers, Ian.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Nov-2008 19:02:16   

Hi Ian.

  • Please always provide the runtime library version you are using.

  • Are the entities participating in inheritance (per entity, per entity hierarchy?). Could you post the relation between the involved entities?

  • Maybe this is not the problem, but I suggest check for null on the result, this could lead to a NullReferenceException too. Check this.

David Elizondo | LLBLGen Support Team
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 24-Nov-2008 00:53:55   

Hi,

I'm using 2.6.8.1013.

Please see the attachment for the hierarchy.

Its not the result as the exception is thrown even without trying to cast the result. (I think you can tell this from the stack trace wink )

Cheers, Ian.

Attachments
Filename File size Added on Approval
contact.jpg 28,857 24-Nov-2008 00:55.12 Approved
Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 24-Nov-2008 09:45:10   

If you are not using an Aggregate, then try using adapter.FetchTypedList() method, instead of the GetScalar() method.

Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 24-Nov-2008 14:05:14   

I've already got it working with FetchEntity with unique constraint. Its just not very cool that this code should have stopped working for no apparent reason!

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 24-Nov-2008 15:12:23   

The thing is that GetScalar() expects an Aggregate to be applied on the selected field, or a GroupByCollection as in the overload you are using.

We'll check to see if a null parameter check would be appropriate to add here.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 24-Nov-2008 18:14:50   

We will look into it.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 25-Nov-2008 10:40:09   

Bug in runtime, working on fix.

See attached dll for the fix. It was an edge case which triggered this: adapter, getscalar, inheritance (targetperentity) and no relation collection. THe routine which crashed assumed the relationcollection was always there, and which was OK, unless the getscalar routine was called with the parameters you passed in.

Frans Bouma | Lead developer LLBLGen Pro
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 19-Dec-2008 04:02:16   

Thanks for the great support. sunglasses