Retrieving a specific row?

2 posts, 0 answers
  1. Derek
    Derek avatar
    118 posts
    Member since:
    Oct 2008

    Posted 18 Dec 2013 Link to this post

    Evaluating the OpenAccess ORM, but some things aren't clear. I'm sure this is simple, but I just don't get it.

    We are trying to retrieve a specific row from a table (FrequencyTypes), using the a value which is the PK. What we'd like to do is retrieve a row into a variable, and then use the values to do a few things.
    Using dbContext As New EntitiesModel
                Dim lFreq As New FrequencyType
                lFreq=dbContext.FrequencyTypes.????[what goes here?]
    end using
    The context is being resolved property, as we're able to perform other actions, but not sure how to go about this.
  2. Boyan
    Boyan avatar
    100 posts

    Posted 20 Dec 2013 Link to this post

    Hello Derek,

    In order to retrieve a single row from the OpenAccess context in accordance with given criteria you could use one of the following LINQ methods First, FirstOrDefault, Single or SingleOrDefault.
    Here is an example of this approach:
    Dim context = New EntitiesModel1()
    Using context
        Dim primaryKeyValue As Integer = GetPrimaryKey()
        Dim retrievedRow = context.FrequencyTypes.FirstOrDefault(Function(x) x.Id = primaryKeyValue)
    End Using

    More on how to use OpenAccess ORM with LINQ can be found in this documentation section. Additionally I would recommend looking through our Samples Kit which provides a number of real-life examples including working with LINQ.

    Do not hesitate to contact us in case you have any further questions.

    OpenAccess ORM Q3 2013 simplifies your model operations even further providing you with greater flexibility. Check out the list of new features shipped with our latest release!
  3. DevCraft banner
Back to Top