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

Error in Car Rental Quick Start (Your first application)

5 Answers 93 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.
Will
Top achievements
Rank 1
Will asked on 02 Nov 2009, 03:15 AM
Hey Group,
I'm getting an exception when trying to compile my first attempt at using OpenAccess.

It is the Quick Start Car rental example in the help documentation.

The code I pasted from the documentation:
Private cachedScope As IObjectScope 
    Private scopeHolder As CarRentMaster 
 
    Protected Sub Page_Init(ByVal sender As ObjectByVal e As EventArgs) Handles Me.Init 
 
        scopeHolder = CType(Me.Master, CarRentMaster) 
        cachedScope = scopeHolder.Scope 
    End Sub 
 
both lines in the page_init are erroring as follows:
    Value of type 'System.Web.UI.MasterPage' cannot be converted to 'CarRentalWebsite.CarRentMaster'.
    'Scope' is not a member of 'CarRentalWebsite.CarRentMaster'.

I don't suspect that this is actually a problem with the ORM itself so point me to another forum if I need to be there.

Many Thanks
Will


5 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 02 Nov 2009, 05:31 PM
Hello Will,

Is it possible that you have missed to inherit from System.Web.UI.MasterPage in your master page file? Also it seems that somehow the definition of the scope in your mater page is missing. Can you please alter the code behind of your master page to look something similar to this:
Namespace CarRentWebSite
    Partial Public Class CarRentMaster
        Inherits System.Web.UI.MasterPage
        Private scope_Renamed As IObjectScope = ObjectScopeProvider1.GetNewObjectScope()
 
        Public Property Scope() As IObjectScope
            Get
                Return scope_Renamed
            End Get
            Set(ByVal value As IObjectScope)
                scope_Renamed = value
            End Set
        End Property
 
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
 
        End Sub
        Public Overrides Sub Dispose()
            scope_Renamed.Dispose()
            MyBase.Dispose()
        End Sub
    End Class
End Namespace
Please do let us know if the above solutions solves your problem.

Greetings,
Petar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Will
Top achievements
Rank 1
answered on 03 Nov 2009, 05:38 AM
Thanks Petar,
I added the following to the top of my content page and that allowed me to build the solution:
Imports CarRentalWebsite.CarRentWebsite 

Now I get the following Error when running the site.
It happens on the following line from my code above.
scopeHolder = CType(Me.Master, CarRentMaster)  

Unable to cast object of type 'ASP.carrentmaster_master' to type 'CarRentalWebsite.CarRentWebsite.CarRentMaster'."}

Thanks for your help with this.
If you are aware of a better quick start tutorial than the one in the help documentation then I'd gladly take a look at it.  I've noticed a few things in the OpenAccess help that appear to be typos.

Thanks Again!
Will



0
PetarP
Telerik team
answered on 05 Nov 2009, 03:10 PM
Hi Will,

We were unable to reproduce this problem and we cannot evaluate what exactly is causing it. Can you please download the completed example that is available in our code library and see if it works for you.
There is another tutorial that is recommended for beginners in Telerik OpenAccess ORM made by our partners Falafel. You can download the pdf format of this guide from here.


All the best,
Petar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Eric
Top achievements
Rank 2
answered on 05 Jan 2010, 05:37 PM
I am getting the same error as mentioned by Will.   I compared the seeRates.aspx.vb pages from the downloaded project with the one I am creating following the explanation from the Telerik OpenAccess ORM Programmers Guide and I realized that a small difference is taking place. It seems that the version of the downloaded project is wapping the code in the NameSpace CarRentWebSite but they is no mention in the guide to do so.  I am not sure why we have to do this, maybe you could you explain it?

Here are the two versions:

Downloaded seeRates.aspx.vb
Imports Microsoft.VisualBasic 
Imports System 
Imports System.Collections.Generic 
Imports System.Linq 
Imports System.Web 
Imports System.Web.UI 
Imports System.Web.UI.WebControls 
Imports Telerik.OpenAccess 
Imports Telerik.OpenAccess.Query 
Imports OpenAccessData 
 
Namespace CarRentWebSite 
    Partial Public Class SeeRates 
        Inherits System.Web.UI.Page 
        Private cachedScope As IObjectScope 
        Private scopeHolder As CarRentMaster 
        Protected Sub Page_Init(ByVal sender As ObjectByVal e As EventArgs) 
            scopeHolder = CType(Me.Master, CarRentMaster) 
            cachedScope = scopeHolder.Scope 
        End Sub 
        Protected Sub Page_Load(ByVal sender As ObjectByVal e As EventArgs) 
            Dim query As String = "select * from RentalRateExtent" 
            Dim queryResult As IQuery = cachedScope.GetOqlQuery(query) 
            queryResult.ForwardsOnly = False 
            Dim result As IQueryResult = queryResult.Execute() 
            RadGrid1.DataSource = result 
            RadGrid1.DataBind() 
        End Sub 
    End Class 
End Namespace 


My version of seeRates.aspx.vb
Imports Telerik.OpenAccess 
Imports Telerik.OpenAccess.Query 
Imports OpenAccessData 
 
  Partial Public Class SeeRates 
    Inherits System.Web.UI.Page 
 
    Private cachedScope As IObjectScope 
    Private scopeHolder As CarRentMaster 
 
    Protected Sub Page_Init(ByVal sender As ObjectByVal e As EventArgs) Handles Me.Init 
    scopeHolder = CType(Me.Master, CarRentMaster) 
    cachedScope = scopeHolder.Scope 
    End Sub 
 
    Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load 
 
    End Sub 
 
  End Class 

0
PetarP
Telerik team
answered on 08 Jan 2010, 10:53 AM
Hi Eric ,

This code should not be compilable if it is not in the same namespace with the master page. Having that in mind you should not be getting runtime errors but compile-time errors. Can you please open a support thread and send us your project? We will really appreciate your cooperation on that issue. Thank you in advance.

Best wishes,
Petar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Getting Started
Asked by
Will
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Will
Top achievements
Rank 1
Eric
Top achievements
Rank 2
Share this question
or