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

Dim scope As IObjectScope Not Working

4 Answers 82 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Lynn
Top achievements
Rank 2
Lynn asked on 25 Apr 2010, 07:31 PM
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

4 Answers, 1 is accepted

Sort by
0
Serge
Telerik team
answered on 26 Apr 2010, 08:22 AM
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.
0
Lynn
Top achievements
Rank 2
answered on 26 Apr 2010, 02:43 PM
Serge,

Sorry, I had tried it both ways.  See the screen capture attached to this message.
0
Accepted
Serge
Telerik team
answered on 26 Apr 2010, 03:43 PM
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.
0
Lynn
Top achievements
Rank 2
answered on 26 Apr 2010, 10:26 PM
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
Tags
Getting Started
Asked by
Lynn
Top achievements
Rank 2
Answers by
Serge
Telerik team
Lynn
Top achievements
Rank 2
Share this question
or