Object Reference Not Set

4 posts, 0 answers
  1. Mike
    Mike avatar
    31 posts
    Member since:
    Apr 2009

    Posted 12 Mar 2013 Link to this post

    I am getting the following exception:
    Object reference not set to an instance of an object.
    When running this linq query:
    Dim result = (From u As DB1.User In dbContext1.Users
                     Join p As DB2.Person In dbContext2.People On p.LoginName Equals u.Email
                     Select u, p).ToList
    The Users and People tables exist in different databases so this is in essence a cross database join.
    Every record in the users table must have an email address but not every person in the persons table must have a login name hence the reason for the join not being outer.
    I believe the issue is probably being cased by the join but have no idea what I can do to fix this issue?
    After further testing I have now implemented the following LINQ change:
    Dim result = (From u As DB1.User In dbContext1.Users
                     Join p As DB2.Person In dbContext.People On p.LoginName Equals u.Email
                     Where Not p.LoginName Is Nothing
                     Select u, p).ToList
    I now have the following exception raised:
    Identifier 'LoginName' is not a parameter or variable or field of 'DbContext.User'. If 'LoginName' is a property please add the FieldAlias or Storage attribute to it or declare it as a field's alias.
    If you look at the LINQ statement, Login name is a field of Person NOT User. Why is Telerik ORM resolving p.LoginName as u.LoginName.
    This is mental. All I want to do is a simple inner join!!
  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 15 Mar 2013 Link to this post

    Hello Mike,

    The actual problem with these queries is that they use contexts from different models or databases. Such scenarios are not supported by OpenAccess - all persistent types used in a Linq query should be part of the same model and accessible from the same context.

    The only way to execute this query would be to call dbContext1.Users.ToList() and dbContext2.People.ToList(), so the join is done in memory.

    Greetings,
    Alexander
    the Telerik team
    OpenAccess ORM Q1 2013 is out featuring Multi-Diagrams, Persistent Data Stream Support and much more. Check out all of the latest highlights.
  3. DevCraft banner
  4. Mike
    Mike avatar
    31 posts
    Member since:
    Apr 2009

    Posted 15 Mar 2013 Link to this post

    Thanks for the response. I understand why but am a little disappointed. We have many projects that use cross database joins which we were considering moving to Telerik ORM but I guess we'll have to rethink this for the time being.
  5. Ivailo
    Admin
    Ivailo avatar
    318 posts

    Posted 20 Mar 2013 Link to this post

    Hi Mike,

    Unfortunately the support for cross-database joins is currently not in our short term plans.

    However, you might consider using OpenAccess ORM due to any of the other unique features we are offering in comparison with alternative ORMs or our extended support for web services in N-Tier applications. I hope those features will be applicable for your scenario.


    Kind regards,
    Ivailo
    the Telerik team
    Free Webinar: OpenAccess Integration in Sitefinity. SIGN UP NOW.
Back to Top