New Posts New Posts RSS Feed: Navigation property null ref exception
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Navigation property null ref exception

 Post Reply Post Reply
Author
dpollot44 View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Jan-2010
Location: Rochester NY
Posts: 24
Post Options Post Options   Quote dpollot44 Quote  Post ReplyReply Direct Link To This Post Topic: Navigation property null ref exception
    Posted: 20-Jul-2010 at 3:26pm
I have a couple of entities joined by navigation properties, Transaction and TransactionDescription.  In this case, TransactionDescription is the principal role (0..1) and Transaction is the dependent role (*).  Transaction has a composite key on it made up of three columns, however none of those columns/properties are part of the association (they're joined by TxCode on one and TxnCode on another).  The Edmx is completely valid as far as entity is concerned, and I've stripped away all developer involvement in a bare bones IdeaBlade 2-tier application consuming this edmx.  I've made sure that I can successfully query TransactionDescription, however Transaction blows chunks all over the place when I try a simple .FirstOrDefault()

Here's the stack trace
Object reference not set to an instance of an object.
   at IdeaBlade.EntityModel.Entity.GetValueRaw(DataEntityProperty property, EntityVersion version)
   at IdeaBlade.EntityModel.EntityWrapper.<GetValuesRaw>b__9(DataEntityProperty p)
   at System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at IdeaBlade.EntityModel.EntityWrapper.GetValuesRaw(IEnumerable`1 properties)
   at IdeaBlade.EntityModel.EntityWrapper.FindRelatedWrappers(EntityRelationLink relationLink, Boolean includeDeleted)
   at IdeaBlade.EntityModel.EntityWrapper.FindRelatedWrapper(EntityRelationLink relationLink, Boolean includeDeleted)
   at IdeaBlade.EntityModel.ScalarEntityReference`1.FindToEntity()
   at IdeaBlade.EntityModel.ScalarEntityReference`1.FixupReferences()
   at IdeaBlade.EntityModel.EntityWrapper.<FixupReferences>b__13(EntityReferenceBase eref)
   at IdeaBlade.Core.EnumerableFns.ForEach[T](IEnumerable`1 items, Action`1 action)
   at IdeaBlade.EntityModel.EntityWrapper.FixupReferences()
   at IdeaBlade.EntityModel.EntityWrapper.TrackChanged(EntityChangedEventArgs e)
   at IdeaBlade.EntityModel.EntityGroup.OnEntityChanged(EntityChangedEventArgs e)
   at IdeaBlade.EntityModel.EntityGroup.AddQueriedEntity(EntityWrapper wrapper)
   at IdeaBlade.EntityModel.EntityGroup.LoadEntity(EntityWrapper sourceWrapper, MergeStrategy mergeStrategy, Boolean& rowUpdated)
   at IdeaBlade.EntityModel.EntityMerger.MergeEntityCore(EntityWrapper sourceWrapper, EntityGroup targetEntityGroup)
   at IdeaBlade.EntityModel.EntityMerger.MergeEntity(EntityWrapper sourceWrapper, EntityGroup targetEntityGroup, NavigationContext context)
   at IdeaBlade.EntityModel.EntityMerger.MergeEntity(EntityWrapper sourceWrapper, NavigationContext context)
   at IdeaBlade.EntityModel.EntityQueryResult.UpdateDataSet(EntityDataBlock block, NavigationContext context)
   at IdeaBlade.EntityModel.EntityDataBlock.Resolve(EntityQueryResult helper)
   at IdeaBlade.EntityModel.EntityQueryResultCollection..ctor(DataQueryResultCollection dqResults, EntityManager entityManager, MergeStrategy mergeStrategy)
   at IdeaBlade.EntityModel.EntityManager.MergeAndReturnUsingCache(IEntityFinder finder, DataQueryResultCollection dqResults)
   at IdeaBlade.EntityModel.EntityManager.ProcessFetchedData(DataQueryResultCollection dqResults, IEntityFinder finder)
   at IdeaBlade.EntityModel.EntityManager.ExecuteFetch(IEntityFinder finder)
   at IdeaBlade.EntityModel.EntityQueryFinder.Execute()
   at IdeaBlade.EntityModel.EntityManager.ExecuteQueryCore(IEntityQuery query, Boolean isAsync)
   at IdeaBlade.EntityModel.EntityQuery`1.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
   at Testing.Client.MainWindow..ctor() in C:\Users\dpollot.MANNING-NAPIER\Documents\Visual Studio 2010\Projects\Testing\Testing.Client\MainWindow.xaml.cs:line 27

And here's an snippet of the csdl

<EntityType Name="PendingLongTransaction">
          <Key>
            <PropertyRef Name="SysDate" />
            <PropertyRef Name="SetNo" />
            <PropertyRef Name="LtRefer" />
          </Key>
...
</EntityType>
<EntityType Name="TransactionDescription">
          <Key>
            <PropertyRef Name="TxnCode" />
          </Key>
...
</EntityType>

<Association Name="FKPendingTxnTxnDescription">
          <End Type="OpenOrdersMaintenance.Data.PendingLongTransaction" Role="PendingLongTransaction" Multiplicity="*" />
          <End Type="OpenOrdersMaintenance.Data.TransactionDescription" Role="TransactionDescription" Multiplicity="0..1" />
          <ReferentialConstraint>
            <Principal Role="TransactionDescription">
              <PropertyRef Name="TxnCode" />
            </Principal>
            <Dependent Role="PendingLongTransaction">
              <PropertyRef Name="TxCode" />
            </Dependent>
          </ReferentialConstraint>
        </Association>

Any ideas what's going on?
Back to Top
dpollot44 View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Jan-2010
Location: Rochester NY
Posts: 24
Post Options Post Options   Quote dpollot44 Quote  Post ReplyReply Direct Link To This Post Posted: 21-Jul-2010 at 6:12am
Also, just as an FYI, I've tested both ends of this relationship with EF and was able to load them just fine... so it looks as though this could potentially be a bug on your end.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 21-Jul-2010 at 10:10am

Since you've stripped this down to a bare bones sample, would you be willing to zip it and send it to us?  If this application also exhibits the other problem you reported with an OutOfMemoery exception with navigation properties that would be great too.

Back to Top
dpollot44 View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Jan-2010
Location: Rochester NY
Posts: 24
Post Options Post Options   Quote dpollot44 Quote  Post ReplyReply Direct Link To This Post Posted: 21-Jul-2010 at 12:09pm
Absolutely.  To whom shall is end it?  You'll have a problem running it unless you've got an informix database (and the provider) however, but I'm sure the edmx coupled with the stack trace I provided should be a good start.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 21-Jul-2010 at 12:20pm
You can send it to me - kimj at ideablade.com.  I don't need the database, as you say the EDMX, along with other nformation, should be sufficient.  If you also have any debug logs that will help too.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 21-Jul-2010 at 5:27pm
I notice you're running version 6.0.1, which was RC1 of DevForce 2010.   We've made quite a few changes since then, and the RTM version 6.0.3.1 is currently available from our web site, while 6.0.4.0 will be coming later this week.  Please upgrade to a more current version and see if the problems you've been seeing still occur.
Back to Top
dpollot44 View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Jan-2010
Location: Rochester NY
Posts: 24
Post Options Post Options   Quote dpollot44 Quote  Post ReplyReply Direct Link To This Post Posted: 22-Jul-2010 at 7:21am
6.0.4 broke all my projects...

First, it seems that after updating, I have to remove all the references (to ideablade assemblies like IdeaBlade.EntityModel, IdeaBlade.Core, etc.) and re-add them.  Why is this??? (this will make upgrading an absolute nightmare).

Second, it appears you've gotten rid of PendingEntityResolved??

from my codegen:

                    //this.<#= navigationProperty.Name #>.PendingEntityResolved += (sender, args) => {
                    //    OnPropertyChanged(new PropertyChangedEventArgs("Properties"));
                    //    if (null != callback)
                    //        callback();
                    //};

which yields (for one specific entity) broken code:

                    //this.AssociationParent.PendingEntityResolved += (sender, args) => {
                    //    OnPropertyChanged(new PropertyChangedEventArgs("Properties"));
                    //    if (null != callback)
                    //        callback();
                    //};

I've gotten the project to build, but I'll have to go through and test to be sure that everything still works, and then I'll get to testing the functionality that prompted the upgrade in the first place... I would really like to know how we can circumvent breaking changes (in terms of assembly references) in the future.  Obviously I'll just need to be more diligent about reading the release notes before upgrading next time for the other errors...
Back to Top
dpollot44 View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Jan-2010
Location: Rochester NY
Posts: 24
Post Options Post Options   Quote dpollot44 Quote  Post ReplyReply Direct Link To This Post Posted: 22-Jul-2010 at 7:55am
I jumped the gun on the assembly ref problem.  I had my references set to target specific versions...
we'll either wind up targeting your assemblies directly from the install path as opposed to the gac, or just make sure that we're not targeting specific versions.
Back to Top
dpollot44 View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Jan-2010
Location: Rochester NY
Posts: 24
Post Options Post Options   Quote dpollot44 Quote  Post ReplyReply Direct Link To This Post Posted: 22-Jul-2010 at 8:36am
This release seems to have "sorta fixed" one problem, and not fixed the other.

The problem that it's partially fixed was the misbehaving association between transaction and transaction description...
Here's my calling code:

            var plt = Context.EntityManager.PendingLongTransactions.FirstOrDefault();
            plt.LoadNavigationProperty("PendingTransactionDescription");
            var desc = plt.PendingTransactionDescription;


Here's the LoadNavigationProperty method:

        public override void LoadNavigationProperty(string propertyName)
        {
            switch(propertyName)
            {       
                case "PendingTransactionDescription":
                    this.EntityAspect.GetRelatedEntity<TransactionDescription>(EntityRelations.FKPendingTxnTxnDescription.Role1.Link);                   
                    break;           
            }
        }


It no longer throws a null reference exception, however neither side of the association in terms of navigation properties are returning results (I've tested to be sure that there are actually results for both sides of the association for a given record (and that it still works in EF).

The other problem (where the call to GetRelatedEntity<T>(...) never returns) has not been fixed by the upgrade.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 22-Jul-2010 at 11:47am
I'm not sure I understand why you're calling GetRelatedEntity.  DevForce definitely still supports "asynchronous navigation" and the PendingEntityResolved and PendingEntityListResolved events.  You should be able to directly access plt.PendingTransactionDescription without first calling LoadNavigationProperty and receive either the entity or a pending entity.
 
We've also made codegen updates between versions 6.0.1 and 6.0.4, so you need to be sure to re-save your EDMX so that the code is regenerated.
Back to Top
dpollot44 View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Jan-2010
Location: Rochester NY
Posts: 24
Post Options Post Options   Quote dpollot44 Quote  Post ReplyReply Direct Link To This Post Posted: 22-Jul-2010 at 12:17pm
I'm not sure I understand why you're calling GetRelatedEntity.


We've disabled your "lazy loading" by default because we don't want developers grabbing navigation properties unintentionally and potentially sucking down our entire database while traversing the graph.  I've made sure this behavior can be overridden (by default we traverse your relations and set them to no load), but for the most part we're going to force our developers into calling the LoadNavigationProperty method so that they're explicit about the data they want.  Thus the reason we're calling GetRelatedEntity. 

We've also made codegen updates between versions 6.0.1 and 6.0.4, so you need to be sure to re-save your EDMX so that the code is regenerated.

We do our own code generation with our own t4 templates.  We're able to produce code that mirrors your code genned code, but allows us to do a number of additional things...

DevForce definitely still supports "asynchronous navigation" and the PendingEntityResolved and PendingEntityListResolved events

Those events used to be on EntityWrapper, which we're deriving from (since our objects derive from Entity).  They don't seem to be there anymore after I upgraded to 6.0.4.
Lines like this:

                    this.AssociationParent.PendingEntityResolved += (sender, args) =>
                    {
                        OnPropertyChanged(new PropertyChangedEventArgs("Properties"));
                        if (null != callback)
                            callback();
                    };

used to work, but no longer.  My co-worker is still using version 6.0.1. and I can navigate to the event handlers on his machine, but not mine.  Have they moved somewhere else??

Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 22-Jul-2010 at 1:43pm
The PendingEntityResolved and PendingEntityListResolved events are now available via the EntityAspect.
 
Can you re-send your generated code file? 
Back to Top
dpollot44 View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Jan-2010
Location: Rochester NY
Posts: 24
Post Options Post Options   Quote dpollot44 Quote  Post ReplyReply Direct Link To This Post Posted: 28-Jul-2010 at 7:15am
I've sent the project to you again.

I've checked and double checked that this stuff works out the box using Entity Framework, and I'm definitely using the latest version of DevForce (6.0.4), so I'm really hoping that we can get this resolved, or you can at least point me in the right direction soon.  We'd prefer not to start implementing hackish workarounds to what should be functional navigation properties...
Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post Posted: 29-Jul-2010 at 11:23pm
Thanks.  We're taking a look at it.
Back to Top
akukucka View Drop Down
Newbie
Newbie
Avatar

Joined: 22-Jul-2010
Location: Rochester, NY
Posts: 11
Post Options Post Options   Quote akukucka Quote  Post ReplyReply Direct Link To This Post Posted: 30-Jul-2010 at 2:07pm
Hey ting,

I'm going to be troubleshooting this while Dave is away at VSLive next week.

I just talked to him and he mentioned that a mock .edmx file was created
from a SQL Server database that mimics our schema. He also mentioned that there were some differences between that .edmx and ours.

I was wondering if you could send me the associations from that file (in the SSDL and CSDL) so I could compare it to ours.

Thanks!
Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post Posted: 30-Jul-2010 at 4:53pm
Sure, can you send an email to IdeaBladeSupportTrack at ideablade dot com with [#7238] as the subject line?  Once I have your contact information, I can walk you through what we found.

Edited by ting - 30-Jul-2010 at 4:54pm
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down