Dim scope As IObjectScope Not Working

5 posts, 1 answers
  1. Lynn
    Lynn avatar
    186 posts
    Member since:
    Sep 2006

    Posted 25 Apr 2010 Link to this post

    I am trying to learn the ORM product for the first time and am following the examples in
     http://www.telerik.com/documents/OpenAccess-MadeEasy.pdf  (using VB).

    On page 28 of that manaul, there is a portion of an example that uses

    Dim

     

     

    scope As IObjectScope = ObjectScopeProvider1.ObjectScope()

     

    scope.Transaction.Begin()


    When I code this in my VS2010 window, I receive an error on the "scope.Transaction.Begin()" line of code saying that a "Declaraion is expected." for "scope".  Refer to attached screen copy graphic for entire details.

    Why isn't your example working in my system?  If this is a stupid question, sorry...

    Thanks in advance!

    Lynn
  2. Serge
    Admin
    Serge avatar
    375 posts

    Posted 26 Apr 2010 Link to this post

    Hi Lynn,

     Please note that ObjectScopeProvider1.ObjectScope is in fact a method that returns an object that implements IObjectScope. You have to call it (with brackets '()' ) in order to get the result and correctly assign the variable.

    Dim scope As IObjectScope = ObjectScopeProvider1.ObjectScope()

    Hope this helps.

    Greetings,
    Serge
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
  4. Lynn
    Lynn avatar
    186 posts
    Member since:
    Sep 2006

    Posted 26 Apr 2010 Link to this post

    Serge,

    Sorry, I had tried it both ways.  See the screen capture attached to this message.
  5. Answer
    Serge
    Admin
    Serge avatar
    375 posts

    Posted 26 Apr 2010 Link to this post

    Hi Lynn,
     
    Sorry, I did not notice the main issue here. You cannot just write code in the declaration of a class, in order to compile it you need to move it to a method, maybe a constructor.

    Public Class Class1
        Public Sub New()
            Using scope As IObjectScope = ObjectScopeProvider1.ObjectScope()
                scope.Transaction.Begin()
     
                'Your code here.
     
                scope.Transaction.Commit()
     
            End Using
        End Sub
    End Class

    This example shows a class with a constructor wrapping the Scope in a using clause so that it is disposed of when it is not needed anymore. I would suggest you to have a look at this msdn article.
    Hope this helps.

    Best wishes,
    Serge
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. Lynn
    Lynn avatar
    186 posts
    Member since:
    Sep 2006

    Posted 26 Apr 2010 Link to this post

    Serge,

    I marked this as an answer.  Thanks!  You're right, I was coding along following the example in the OpenAccess-MadeEasy.pdf tutorial and didn't notice that there were a few corners cut in the sample.  I made the functional code a Sub and everything cleared up and worked fine.

    Thanks again!

    Lynn
Back to Top
DevCraft banner