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

telerik openaccess cannot access public property from entity class

1 Answer 21 Views
Miscellaneous
This is a migrated thread and some comments may be shown as answers.
Kevin Cabritit
Top achievements
Rank 1
Kevin Cabritit asked on 11 May 2017, 11:56 PM
 having a project that uses the telerik dataaccess component to edit or add a new blogpost entity.
It seems it can't access a column(URL) in the database/ORM - We always have been using reverse mapping to autogenerate the classes in the ORM project - then build the ORM.dll file. As indicated below in the code file, the missing property URL is part of the object but for some reason it fails to read that property.
When creating a new record using the openaccessdatasource - onInserting and OnInserted events. it throws out the below error
Exception type: InvalidOperationExceptionException message: A public property with name 'URL' is not available on type 'ORM.Blogpost'. at Telerik.OpenAccess.RT.DataSource.OpenAccessDataSourceView.GetPublicProperty(String name, Type type) at Telerik.OpenAccess.RT.DataSource.OpenAccessDataSourceView.FillPublicPropertiesOnPersistentInstance(IDictionary propertyValues, PersistenceCapable pc, ParameterCollection parameters) at Telerik.OpenAccess.RT.DataSource.OpenAccessDataSourceView.ExecuteInsert(IDictionary values) at System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) at System.Web.UI.WebControls.FormView.HandleInsert(String commandArg, Boolean causesValidation) at System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) at System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) at System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) at System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Any ideas on why this might happen?

Here is the form page .aspx and .cs file

<telerik:OpenAccessDataSource ID="BlogpostOpenAccessDataSource" runat="server" ObjectContextProvider="ORM.ObjectScopeProvider1, ORM"TypeName="ORM.Blogpost" Where="CompanyId == @CompanyId AND BlogPostId == @BlogPostId"OnInserted="BlogpostOpenAccessDataSource_Inserted" OnInserting="BlogpostOpenAccessDataSource_Inserting"OnUpdated="BlogpostOpenAccessDataSource_Updated" OnUpdating="BlogpostOpenAccessDataSource_Updating"><WhereParameters><asp:SessionParameter Name="CompanyId" SessionField="companyId" DbType="Guid" /><asp:SessionParameter Name="BlogPostId" SessionField="blogPostId" DbType="Guid" /></WhereParameters></telerik:OpenAccessDataSource>
 Run code snippet
Expand snippet

protected void BlogpostOpenAccessDataSource_Inserting(object sender, OpenAccessDataSourceChangingEventArgs e){ ORM.Blogpost newBlogpost = (ORM.Blogpost)e.Entity; newBlogpost.Url = ""; newBlogpost.CreateDateTime = DateTime.UtcNow; newBlogpost = SetCreateUpdateBlogPost(newBlogpost);}protected void BlogpostOpenAccessDataSource_Inserted(object sender, OpenAccessDataSourceChangedEventArgs e){ ORM.Blogpost newBlogpost = (ORM.Blogpost)e.Entity; blogPostId = newBlogpost.BlogPostId;AddBlogPostMemberType();AddBlogPostCinema();Response.Redirect("~/BlogPost/BlogPost_list.aspx?Information=Successfully Inserted");}protected ORM.Blogpost SetCreateUpdateBlogPost(ORM.Blogpost blogpost){RadDatePicker validStartDateTime = FormView1.FindControl("ValidStartDateTime") as RadDatePicker;RadDatePicker validFinishDateTime = FormView1.FindControl("ValidFinishDateTime") as RadDatePicker;TextBox subjectTextBox = FormView1.FindControl("SubjectTextBox") as TextBox;RadComboBox cmbBlogPostSection = FormView1.FindControl("cmbBlogPostSection") as RadComboBox;TextBox textTextBox = FormView1.FindControl("TextTextBox") as TextBox;CheckBox isStickyCheckBox = FormView1.FindControl("IsStickyCheckBox") as CheckBox;CheckBox isPublicCheckBox = FormView1.FindControl("IsPublicCheckBox") as CheckBox;RadComboBox cmbDestination = FormView1.FindControl("cmbDestination") as RadComboBox; blogpost.ValidStartDateTime = (DateTime)validStartDateTime.SelectedDate; blogpost.ValidFinishDateTime = (DateTime)validFinishDateTime.SelectedDate; blogpost.Subject = subjectTextBox.Text; blogpost.BlogPostSectionId = Int16.Parse(cmbBlogPostSection.SelectedValue); blogpost.Text = textTextBox.Text; blogpost.IsSticky = isStickyCheckBox.Checked; blogpost.IsPublic = isPublicCheckBox.Checked; blogpost.CompanyId = Master.companyId; ORM.Company Company = DAL.DataClasses.Company.GetCompanyObjectById(Master.companyId); blogpost.CountryId = Company.CountryId; blogpost.LanguageId = short.Parse(Company.Country.LanguageId.ToString());//urlif (cmbDestination.SelectedItem.Text == "URL"){TextBox urlTextBox = FormView1.FindControl("URLTextBox") as TextBox; blogpost.Url = urlTextBox.Text;}else{ blogpost.Url = "";}//... some code here for other blogpost fieldsreturn blogpost;}

Here is the generated blogpost.cs file in the ORM project
using System; using System.Collections.Generic; namespace ORM {//Generated by Telerik OpenAccesspublic partial class Blogpost{//The 'no-args' constructor required by OpenAccess.public Blogpost(){}[Telerik.OpenAccess.FieldAlias("blogPostId")]public Guid BlogPostId{ get { return blogPostId; }set { this.blogPostId = value; }}[Telerik.OpenAccess.FieldAlias("authorUserId")]public Guid AuthorUserId{ get { return authorUserId; }set { this.authorUserId = value; }}[Telerik.OpenAccess.FieldAlias("autoPostTypeId")]public int? AutoPostTypeId{ get { return autoPostTypeId; }set { this.autoPostTypeId = value; }}[Telerik.OpenAccess.FieldAlias("blogPostSectionId")]public short BlogPostSectionId{ get { return blogPostSectionId; }set { this.blogPostSectionId = value; }}[Telerik.OpenAccess.FieldAlias("companyId")]public Guid? CompanyId{ get { return companyId; }set { this.companyId = value; }}[Telerik.OpenAccess.FieldAlias("competitionId")]public Guid? CompetitionId{ get { return competitionId; }set { this.competitionId = value; }}[Telerik.OpenAccess.FieldAlias("countryId")]public short? CountryId{ get { return countryId; }set { this.countryId = value; }}[Telerik.OpenAccess.FieldAlias("createDateTime")]public DateTime CreateDateTime{ get { return createDateTime; }set { this.createDateTime = value; }}[Telerik.OpenAccess.FieldAlias("isAutoGenerated")]public bool IsAutoGenerated{ get { return isAutoGenerated; }set { this.isAutoGenerated = value; }}[Telerik.OpenAccess.FieldAlias("isPublic")]public bool IsPublic{ get { return isPublic; }set { this.isPublic = value; }}[Telerik.OpenAccess.FieldAlias("isSticky")]public bool IsSticky{ get { return isSticky; }set { this.isSticky = value; }}[Telerik.OpenAccess.FieldAlias("languageId")]public short LanguageId{ get { return languageId; }set { this.languageId = value; }}[Telerik.OpenAccess.FieldAlias("movieDetailId")]public Guid? MovieDetailId{ get { return movieDetailId; }set { this.movieDetailId = value; }}[Telerik.OpenAccess.FieldAlias("offerId")]public Guid? OfferId{ get { return offerId; }set { this.offerId = value; }}[Telerik.OpenAccess.FieldAlias("pageId")]public Guid? PageId{ get { return pageId; }set { this.pageId = value; }}[Telerik.OpenAccess.FieldAlias("promotionId")]public Guid? PromotionId{ get { return promotionId; }set { this.promotionId = value; }}[Telerik.OpenAccess.FieldAlias("shopId")]public Guid? ShopId{ get { return shopId; }set { this.shopId = value; }}[Telerik.OpenAccess.FieldAlias("subject")]public string Subject{ get { return subject; }set { this.subject = value; }}[Telerik.OpenAccess.FieldAlias("text")]public string Text{ get { return text; }set { this.text = value; }}[Telerik.OpenAccess.FieldAlias("url")]public string Url{ get { return url; }set { this.url = value; }}[Telerik.OpenAccess.FieldAlias("validFinishDateTime")]public DateTime ValidFinishDateTime{ get { return validFinishDateTime; }set { this.validFinishDateTime = value; }}//more properties}} having a project that uses the telerik dataaccess component to edit or add a new blogpost entity.
It seems it can't access a column(URL) in the database/ORM - We always have been using reverse mapping to autogenerate the classes in the ORM project - then build the ORM.dll file. As indicated below in the code file, the missing property URL is part of the object but for some reason it fails to read that property.
When creating a new record using the openaccessdatasource - onInserting and OnInserted events. it throws out the below error
Exception type: InvalidOperationExceptionException message: A public property with name 'URL' is not available on type 'ORM.Blogpost'. at Telerik.OpenAccess.RT.DataSource.OpenAccessDataSourceView.GetPublicProperty(String name, Type type) at Telerik.OpenAccess.RT.DataSource.OpenAccessDataSourceView.FillPublicPropertiesOnPersistentInstance(IDictionary propertyValues, PersistenceCapable pc, ParameterCollection parameters) at Telerik.OpenAccess.RT.DataSource.OpenAccessDataSourceView.ExecuteInsert(IDictionary values) at System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) at System.Web.UI.WebControls.FormView.HandleInsert(String commandArg, Boolean causesValidation) at System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) at System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) at System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) at System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Any ideas on why this might happen?

Here is the form page .aspx and .cs file

<telerik:OpenAccessDataSource ID="BlogpostOpenAccessDataSource" runat="server" ObjectContextProvider="ORM.ObjectScopeProvider1, ORM"TypeName="ORM.Blogpost" Where="CompanyId == @CompanyId AND BlogPostId == @BlogPostId"OnInserted="BlogpostOpenAccessDataSource_Inserted" OnInserting="BlogpostOpenAccessDataSource_Inserting"OnUpdated="BlogpostOpenAccessDataSource_Updated" OnUpdating="BlogpostOpenAccessDataSource_Updating"><WhereParameters><asp:SessionParameter Name="CompanyId" SessionField="companyId" DbType="Guid" /><asp:SessionParameter Name="BlogPostId" SessionField="blogPostId" DbType="Guid" /></WhereParameters></telerik:OpenAccessDataSource>
 Run code snippet
Expand snippet

protected void BlogpostOpenAccessDataSource_Inserting(object sender, OpenAccessDataSourceChangingEventArgs e){ ORM.Blogpost newBlogpost = (ORM.Blogpost)e.Entity; newBlogpost.Url = ""; newBlogpost.CreateDateTime = DateTime.UtcNow; newBlogpost = SetCreateUpdateBlogPost(newBlogpost);}protected void BlogpostOpenAccessDataSource_Inserted(object sender, OpenAccessDataSourceChangedEventArgs e){ ORM.Blogpost newBlogpost = (ORM.Blogpost)e.Entity; blogPostId = newBlogpost.BlogPostId;AddBlogPostMemberType();AddBlogPostCinema();Response.Redirect("~/BlogPost/BlogPost_list.aspx?Information=Successfully Inserted");}protected ORM.Blogpost SetCreateUpdateBlogPost(ORM.Blogpost blogpost){RadDatePicker validStartDateTime = FormView1.FindControl("ValidStartDateTime") as RadDatePicker;RadDatePicker validFinishDateTime = FormView1.FindControl("ValidFinishDateTime") as RadDatePicker;TextBox subjectTextBox = FormView1.FindControl("SubjectTextBox") as TextBox;RadComboBox cmbBlogPostSection = FormView1.FindControl("cmbBlogPostSection") as RadComboBox;TextBox textTextBox = FormView1.FindControl("TextTextBox") as TextBox;CheckBox isStickyCheckBox = FormView1.FindControl("IsStickyCheckBox") as CheckBox;CheckBox isPublicCheckBox = FormView1.FindControl("IsPublicCheckBox") as CheckBox;RadComboBox cmbDestination = FormView1.FindControl("cmbDestination") as RadComboBox; blogpost.ValidStartDateTime = (DateTime)validStartDateTime.SelectedDate; blogpost.ValidFinishDateTime = (DateTime)validFinishDateTime.SelectedDate; blogpost.Subject = subjectTextBox.Text; blogpost.BlogPostSectionId = Int16.Parse(cmbBlogPostSection.SelectedValue); blogpost.Text = textTextBox.Text; blogpost.IsSticky = isStickyCheckBox.Checked; blogpost.IsPublic = isPublicCheckBox.Checked; blogpost.CompanyId = Master.companyId; ORM.Company Company = DAL.DataClasses.Company.GetCompanyObjectById(Master.companyId); blogpost.CountryId = Company.CountryId; blogpost.LanguageId = short.Parse(Company.Country.LanguageId.ToString());//urlif (cmbDestination.SelectedItem.Text == "URL"){TextBox urlTextBox = FormView1.FindControl("URLTextBox") as TextBox; blogpost.Url = urlTextBox.Text;}else{ blogpost.Url = "";}//... some code here for other blogpost fieldsreturn blogpost;}

Here is the generated blogpost.cs file in the ORM project
using System; using System.Collections.Generic; namespace ORM {//Generated by Telerik OpenAccesspublic partial class Blogpost{//The 'no-args' constructor required by OpenAccess.public Blogpost(){}[Telerik.OpenAccess.FieldAlias("blogPostId")]public Guid BlogPostId{ get { return blogPostId; }set { this.blogPostId = value; }}[Telerik.OpenAccess.FieldAlias("authorUserId")]public Guid AuthorUserId{ get { return authorUserId; }set { this.authorUserId = value; }}[Telerik.OpenAccess.FieldAlias("autoPostTypeId")]public int? AutoPostTypeId{ get { return autoPostTypeId; }set { this.autoPostTypeId = value; }}[Telerik.OpenAccess.FieldAlias("blogPostSectionId")]public short BlogPostSectionId{ get { return blogPostSectionId; }set { this.blogPostSectionId = value; }}[Telerik.OpenAccess.FieldAlias("companyId")]public Guid? CompanyId{ get { return companyId; }set { this.companyId = value; }}[Telerik.OpenAccess.FieldAlias("competitionId")]public Guid? CompetitionId{ get { return competitionId; }set { this.competitionId = value; }}[Telerik.OpenAccess.FieldAlias("countryId")]public short? CountryId{ get { return countryId; }set { this.countryId = value; }}[Telerik.OpenAccess.FieldAlias("createDateTime")]public DateTime CreateDateTime{ get { return createDateTime; }set { this.createDateTime = value; }}[Telerik.OpenAccess.FieldAlias("isAutoGenerated")]public bool IsAutoGenerated{ get { return isAutoGenerated; }set { this.isAutoGenerated = value; }}[Telerik.OpenAccess.FieldAlias("isPublic")]public bool IsPublic{ get { return isPublic; }set { this.isPublic = value; }}[Telerik.OpenAccess.FieldAlias("isSticky")]public bool IsSticky{ get { return isSticky; }set { this.isSticky = value; }}[Telerik.OpenAccess.FieldAlias("languageId")]public short LanguageId{ get { return languageId; }set { this.languageId = value; }}[Telerik.OpenAccess.FieldAlias("movieDetailId")]public Guid? MovieDetailId{ get { return movieDetailId; }set { this.movieDetailId = value; }}[Telerik.OpenAccess.FieldAlias("offerId")]public Guid? OfferId{ get { return offerId; }set { this.offerId = value; }}[Telerik.OpenAccess.FieldAlias("pageId")]public Guid? PageId{ get { return pageId; }set { this.pageId = value; }}[Telerik.OpenAccess.FieldAlias("promotionId")]public Guid? PromotionId{ get { return promotionId; }set { this.promotionId = value; }}[Telerik.OpenAccess.FieldAlias("shopId")]public Guid? ShopId{ get { return shopId; }set { this.shopId = value; }}[Telerik.OpenAccess.FieldAlias("subject")]public string Subject{ get { return subject; }set { this.subject = value; }}[Telerik.OpenAccess.FieldAlias("text")]public string Text{ get { return text; }set { this.text = value; }}[Telerik.OpenAccess.FieldAlias("url")]public string Url{ get { return url; }set { this.url = value; }}[Telerik.OpenAccess.FieldAlias("validFinishDateTime")]public DateTime ValidFinishDateTime{ get { return validFinishDateTime; }set { this.validFinishDateTime = value; }}//more properties}}

1 Answer, 1 is accepted

Sort by
0
Kevin Cabritit
Top achievements
Rank 1
answered on 12 May 2017, 12:00 AM
My apologies for the formatting on the code.
Tags
Miscellaneous
Asked by
Kevin Cabritit
Top achievements
Rank 1
Answers by
Kevin Cabritit
Top achievements
Rank 1
Share this question
or