This is a migrated thread and some comments may be shown as answers.

Object Reference Not Set

3 Answers 67 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mike
Top achievements
Rank 1
Mike asked on 12 Mar 2013, 04:16 PM
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!!

3 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 15 Mar 2013, 09:14 AM
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.
0
Mike
Top achievements
Rank 1
answered on 15 Mar 2013, 10:56 AM
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.
0
Ivailo
Telerik team
answered on 20 Mar 2013, 01:16 PM
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.
Tags
LINQ (LINQ specific questions)
Asked by
Mike
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Mike
Top achievements
Rank 1
Ivailo
Telerik team
Share this question
or