DataAccess and Navigation

Thread is closed for posting
2 posts, 0 answers
  1. Rich
    Rich avatar
    1 posts
    Member since:
    Nov 2014

    Posted 16 Nov 2014 Link to this post

    I'm new to the DataAccess tool, and i've recently been given the task of converting a vb project to a c# project.

    I've got the data model moved and it seems correct, at least when i look at it, it has the the properties, implementation and navigation. and they look correct.

    I can't seem to access the Navigation portion. when i call the code.  the base table properties are all available, but the navigation is missing, even though visible in the model.

    The vb portion works fine but not the c# version.   Thoughts on what i should look at/might be wrong?

    this works fine:
    DBContext.WebApps.FirstOrDefault((WebApp f) => f.appGUID.ToString() == WebAppsGuid);

    or any time the properties are used, but if 

    DBContext.WebSessions.FirstOrDefault((WebSession f) => f.WebAppId == qWebApp.Id & f.WebUser.AspNetUserId == CurrentClient.Id & f.Expired == 0);

    specifically: f.WebUser.AspNetUserId when i try to use the navigation, it's just not there to use.

    Thoughts on what i should look at/might be wrong?
  2. Boris Georgiev
    Boris Georgiev avatar
    190 posts

    Posted 19 Nov 2014 Link to this post

    Hello Rich,

    In the lamba expression, you are checking for the "AspNetUserId" property of the reference navigation property without checking if the reference WebUser exists at all. Also you are using the '&' operator instead the '&&' operator which will evaluate the entire statement, instead of returning false if the first comparison fails.

    Could you try to replace the lambda expression with this code:
    DBContext.WebSessions.FirstOrDefault((WebSession f) => f.WebAppId == qWebApp.Id && f.WebUser != null && f.WebUser.AspNetUserId == CurrentClient.Id && f.Expired == 0);

    I hope that helps. If any other questions arise, do not hesitate to contact us again.

    Boris Georgiev
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
Back to Top