Simple Vb Linq question

7 posts, 0 answers
  1. Chris
    Chris avatar
    23 posts
    Member since:
    Feb 2009

    Posted 27 Feb 2009 Link to this post

    Hi,
    I'm trying to figure out how to use LINQ with OA.  I'm not sure I'm on the right course, especially with regard to the .Extent extension.

    Two questions:
    1.  Do I need to use the .Extent extensions?  If not how do I do anything without it.
    2.  I have a few simple lines of code:
            Dim scope As Telerik.OpenAccess.IObjectScope
            scope = OaMsTest1.ObjectScopeProvider1.GetNewObjectScope
            scope.Transaction.Begin()
            Dim ext As IQueryable(Of Category)
            ext = scope.Extent(Of Category)()
            Dim result = From c In ext _
                         Where Not c.CategoryName Is "something" _
                         Select c
            For Each c In result
                Console.WriteLine(c.CategoryName)
            Next

    Now, each Category has a CategoryName field.  Intellisense recognizes it, but I get the following:

    Identifier 'CategoryName' is not a parameter, variable or field of 'OaMsTest1.Category'. If 'CategoryName' is a property please add the FieldAlias attribute to it.

    If I uncomment the following  FieldAlias:

     Private _catName As String
        '<Telerik.OpenAccess.FieldAlias("CategoryName")> _
        Public Property CategoryName() As String
            Get
                Return _catName
            End Get
            Set(ByVal value As String)
                _catName = value
            End Set
        End Property

    Then I get:

    Error    2    OpenAccess Error: The property 'CategoryName' of type 'Category' is declared to be an alias for field 'CategoryName', but such a field does not exist or is transient and not present in the database. [class=OaMsTest1.Category] [field=CategoryName]    C:\Development\OaMsTest1\OaMsTest1\Category.vb    2    


    Anybody have any pointers?

    THanks a million,
    Chris






  2. Chris
    Chris avatar
    23 posts
    Member since:
    Feb 2009

    Posted 27 Feb 2009 Link to this post

    Some progress:
    I now understand that the FieldAlias attribute should contain the internal field for the property's value, not an externally visiable name.  Correct?

    The following seems to work:
     Dim scope As Telerik.OpenAccess.IObjectScope
            scope = OaMsTest1.ObjectScopeProvider1.GetNewObjectScope
            scope.Transaction.Begin()
            Dim ext As IQueryable(Of Category)
            ext = scope.Extent(Of Category)()

            Dim txt As String = "something"
            Dim result = From c In ext _
                         Where Not c.CategoryName = txt _
                         Select c

            For Each c In result
                Console.WriteLine(c.CategoryName)
            Next
  3. DevCraft banner
  4. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 28 Feb 2009 Link to this post

    Hello Chris,
    You are progressing quite fast which is really a good thing. And yes, what you have stated is correct. If you encounter any problems do not hesitate to contact us.

    Best wishes,
    PetarP
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Ryan
    Ryan avatar
    4 posts
    Member since:
    Dec 2008

    Posted 30 Jul 2009 Link to this post

    Hey,

    I'm getting the same error "Identifier 'PersonnelNo' is not a parameter, variable or field of 'LMS_Classes.RegistrationStatu'. If 'PersonnelNo' is a property please add the FieldAlias attribute to it.

    However, I believe it is for a different reason. Here is my LINQ query:

    Dim currentActiveRegistrationStatus As LMS_Classes.RegistrationStatu 
          Try 
             pScope.Transaction.Begin() 
             Dim result As IQueryable(Of LMS_Classes.RegistrationStatu) 
             result = From RS In pScope.Extent(Of LMS_Classes.RegistrationStatu)() _ 
                      Where RS.Registration.PersonnelNo = pPersNo 
                      Select RS 
             currentActiveRegistrationStatus = result.OfType(Of LMS_Classes.RegistrationStatu)().ToList.Item(0) 
          Catch ex As Exception 
             MsgBox("Error: " & ex.Message) 
             currentActiveRegistrationStatus = Nothing 
          End Try 

    Here is my 'RegistrationStatu' class (that contains my Registration object, which contains my personnelNo property)
    Imports System.Collections.Generic 
     
     
    'Generated by Telerik OpenAccess 
    'NOTE: Field declarations and 'Object ID' class implementation are added to the 'designer' file. 
    '      Changes made to the 'designer' file will be overwritten by the wizard.    
    Partial Public Class RegistrationStatu 
     
        'The 'no-args' constructor required by OpenAccess. 
        Public Sub New() 
        End Sub 
     
        <Telerik.OpenAccess.FieldAlias("_registrationStatusID")> _ 
        Public Property RegistrationStatusID() As Integer 
            Get 
                Return _registrationStatusID 
            End Get 
            SetByVal Value As Integer ) 
                Me._registrationStatusID = Value 
            End Set 
        End Property 
      
        <Telerik.OpenAccess.FieldAlias("_isActive")> _ 
        Public Property IsActive() As Boolean 
            Get 
                Return _isActive 
            End Get 
            SetByVal Value As Boolean ) 
                Me._isActive = Value 
            End Set 
        End Property 
      
        <Telerik.OpenAccess.FieldAlias("_lastUpdatedBy")> _ 
        Public Property LastUpdatedBy() As Short 
            Get 
                Return _lastUpdatedBy 
            End Get 
            SetByVal Value As Short ) 
                Me._lastUpdatedBy = Value 
            End Set 
        End Property 
      
        <Telerik.OpenAccess.FieldAlias("_statusDate")> _ 
        Public Property StatusDate() As Date 
            Get 
                Return _statusDate 
            End Get 
            SetByVal Value As Date ) 
                Me._statusDate = Value 
            End Set 
        End Property 
      
        <Telerik.OpenAccess.FieldAlias("_registration")> _ 
        Public Property Registration() As Registration 
            Get 
                Return _registration 
            End Get 
            SetByVal Value As Registration ) 
                Me._registration = Value 
            End Set 
        End Property 
      
    End Class 
     
     

    Here is my 'Registration' class (that contains my personnelNo property)
    Imports System.Collections.Generic 
     
     
    'Generated by Telerik OpenAccess 
    'NOTE: Field declarations and 'Object ID' class implementation are added to the 'designer' file. 
    '      Changes made to the 'designer' file will be overwritten by the wizard.    
    Partial Public Class Registration 
     
        'The 'no-args' constructor required by OpenAccess. 
        Public Sub New() 
        End Sub 
     
        <Telerik.OpenAccess.FieldAlias("_registrationID")> _ 
        Public Property RegistrationID() As Integer 
            Get 
                Return _registrationID 
            End Get 
            SetByVal Value As Integer ) 
                Me._registrationID = Value 
            End Set 
        End Property 
       
       <Telerik.OpenAccess.FieldAlias("_checkInDate")> _ 
        Public Property CheckInDateTime() As Nullable(Of Date
          Get 
             Return _checkInDate 
          End Get 
          Set(ByVal Value As Nullable(Of Date)) 
             Me._checkInDate = Value 
          End Set 
       End Property 
      
       <Telerik.OpenAccess.FieldAlias("_checkOutDate")> _ 
        Public Property CheckOutDateTime() As Nullable(Of Date
          Get 
             Return _checkOutDate 
          End Get 
          Set(ByVal Value As Nullable(Of Date)) 
             Me._checkOutDate = Value 
          End Set 
       End Property 
      
        <Telerik.OpenAccess.FieldAlias("_personnelNo")> _ 
        Public Property PersonnelNo() As Short 
            Get 
                Return _personnelNo 
            End Get 
            SetByVal Value As Short ) 
                Me._personnelNo = Value 
            End Set 
        End Property 
      
        <Telerik.OpenAccess.FieldAlias("_preferredRoomate")> _ 
        Public Property PreferredRoomate() As Short 
            Get 
                Return _preferredRoomate 
            End Get 
            SetByVal Value As Short ) 
                Me._preferredRoomate = Value 
            End Set 
        End Property 
          
    End Class 

    The intellisense works fine (which is how I made the LINQ). Which is why I don't understand why I'm getting the error.

    Any point in the right direction would be appreciated!

    Cheers,

    Ryan


  6. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 31 Jul 2009 Link to this post

    Hi Ryan,
    can you please provide us with some additional information. What version of our product are you using as we fail to see any record of previous downloads of yours.
    Using reverse mapping should apply the proper field attributes to your properties so this should work out fine. If you are using some old version can you please download a free trial of the latest version from our site and check if everything with your project works fine.

    Sincerely yours,
    Petar
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Ryan
    Ryan avatar
    4 posts
    Member since:
    Dec 2008

    Posted 04 Aug 2009 Link to this post

    Hey Petar,

    I am using version 2009.2.701.5.

    I agree it should work fine, but that does not seem to be the case. It seems to appear when I get deeper into each class. If I'm getting a direct property from a class, it's fine, but when I get a property from a class that is a property of a class, then it gives me that error.

    ie. RegistrationStatu.IsActive works fine
         RegistrationStatu.Registration.PersonnelNo does not work.

    Cheers,

    Ryan
  8. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 07 Aug 2009 Link to this post

    Hello Ryan,

    We were unable to reproduce this odd behavior using our latest internal build (2009.2.720.1). I have attached a sample project to the support ticket you opened with the suggestion to upgrade to our latest internal build. If you have any further questions, please do let us know.

    Kind regards,
    Petar
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top
DevCraft banner