locked
Could not find a property on the type specified by the DataObjectTypeName property RRS feed

  • Question

  • User180398699 posted

    Hi - I need some help:

    1. I'm using a ListView using an ObjectDataSource which has CRUD operations implemented by a biz objects layer sitting between the UI and the SQL DB. 

    2. The Biz Objects layer consists of partial classes which extend the functionality of a series of entity objects created by Linq2SQL. 

    3. The ObjectDataSource makes use of DataObjectTypeName which is set to the resume_school entity object generated by Linq2SQL.

    4. The resume_school object has a property - "school" which is a child entity - also created by Linq2SQL.  The school object has it's own properties and is related to the resume_school object via a relationship created by their common "school_id" fields.

    5. I am successfully using, as an example <%# Eval("school.school1") %> to bind to a label control embedded in the Select Template.

    6. Similarly, I am successfully using <%# Bind("school.school1") %> to bind to a textbox control embedded in the Edit Template.

    7. Both of these find and return the correct data from the DB.

    8.  When I click on "Update" while in Edit Mode, I get the following error msg:

    Could not find a property named 'school.school1' on the type specified by the DataObjectTypeName property in ObjectDataSource 'ObjectResumeEducationData'.

    9.  I attempted to add a property "test" to the resume_school class which get and set values from down inside the school entity, but found that "this" as in "this.school.school1" was coming back as null.

    Here is the relevant ASPX:

                <asp:ListView ID="EducationListView" runat="server"
                DataKeyNames="resume_school_id, version"
                DataSourceID="ObjectResumeEducationData"
                OnItemDataBound="EducationListView_ItemDataBound">
                    <LayoutTemplate>
                        <div style="width: 100%" runat="server" id="itemPlaceholder"/>
                    </LayoutTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="EditButton" visible="<%# authToken %>" runat="server" CommandName="Edit" style="color: Blue">Edit</asp:LinkButton>
                        <asp:LinkButton  ID="DeleteSchoolButton" visible="<%# authToken %>"  runat="server"  CommandName="Delete" style="color: Blue">Delete</asp:LinkButton>
                        <div runat="server">
                            <div style="margin: 0; padding: 0;">
                                <div class="employer"><asp:Label ID="SchoolLbl" runat="server" Text='<%# Eval("school.school1") %>' />, <span class="employerlocation"><asp:Label ID="SchoolCityLbl" runat="server" Text='<%# Eval("school.city") %>' />, <asp:Label ID="SchoolStateLbl" runat="server" Text='<%# Eval("school.state") %>' /></span></div>
                                <div class="employerdate"><asp:Label ID="SchoolStartLbl" runat="server" Text='<%# Eval("school.startdate") %>'/> - <asp:Label ID="SchoolEndLbl" runat="server" Text='<%# Eval("school.enddate") %>'/></div>
                            </div>                               
                            <div class="major"><asp:Label ID="SchoolDegreeLbl" runat="server" Text='<%# Eval("school.degree") %>'/></div>
                        </div>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <h3 style="color: #000000; float: left">Edit School</h3>
                        <div style="float: left; padding-left: 10px">
                            <asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" style="color: Blue">Update</asp:LinkButton>
                            <asp:LinkButton ID="CancelButton" runat="server" CommandName="Cancel" style="color: Blue">Cancel</asp:LinkButton>
                        </div>
                        <table style="border: 1px solid black; width: 100%; background-color: LightGray; padding: 7px 7px 7px 7px">
                            <tr>
                                <td class="EditLabel" style="width: 85px">School Name:</td>
                                <td><asp:TextBox ID="SchoolTxtBox" runat="server" Text='<%# Bind("school.school1") %>'/></td>
                            </tr>
                            <tr>
                                <td class="EditLabel">City:</td>
                                <td><asp:TextBox ID="SchoolCityTxtBox" runat="server" Text='<%# Bind("school.city") %>'/></td>
                            </tr>
                            <tr>
                                <td class="EditLabel">State:</td>
                                <td><asp:TextBox ID="SchoolStateTxtBox" runat="server" Text='<%# Bind("school.state") %>' /></td>
                            </tr>                        <tr>
                                <td class="EditLabel">Start Date:</td>
                                <td><asp:TextBox ID="SchoolStartTxtBox" runat="server" Text='<%# Bind("school.startdate") %>' /></td>
                            </tr>                        <tr>
                                <td class="EditLabel">End Date:</td>
                                <td><asp:TextBox ID="SchoolEndTxtBox" runat="server" Text='<%# Bind("school.enddate") %>'/></td>
                            </tr>                        <tr>
                                <td class="EditLabel">Degree:</td>
                                <td><asp:TextBox ID="SchoolDegreeTxtBox" runat="server" Text='<%# Bind("school.degree") %>'/></td>
                            </tr>
                        </table>
                    </EditItemTemplate>
                </asp:ListView>

        <asp:ObjectDataSource
            ID="ObjectResumeEducationData"
            TypeName="resume_school" runat="server"
            DataObjectTypeName="resume_school"
            SelectMethod="Select"
            UpdateMethod="UpdateSchool"
            InsertMethod="Insertresume_school"
            DeleteMethod="Deleteresume_school"
            ConflictDetection="CompareAllValues"
            OldValuesParameterFormatString="oldResumeSchool">
            <SelectParameters>
                <asp:QueryStringParameter name="resume_id" querystringfield="qyd"
                    DbType="Guid"/>
            </SelectParameters>
        </asp:ObjectDataSource>

    Here is the codebehind.  It's not necessarily relevant here, but I've included it because the listview references the function "EducationListView_ItemDataBound":

        protected void EducationListView_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                ListViewDataItem item = e.Item as ListViewDataItem;

                if (item != null)
                {
                    resume_school thisSchool = (resume_school)item.DataItem;

                    Label StartDateLbl = (Label)e.Item.FindControl("SchoolStartLbl");
                    Label EndDateLbl = (Label)e.Item.FindControl("SchoolEndLbl");

                    if (StartDateLbl != null && EndDateLbl != null)
                    {
                        StartDateLbl.Text = thisSchool.school.startdate.Year.ToString();

                        if (thisSchool.school.enddate == null)
                            EndDateLbl.Text = "Present";
                        else
                            EndDateLbl.Text = ((DateTime)thisSchool.school.enddate).Year.ToString();
                    }   
               }
            }
        }

    Here is the relevant code from the biz objects layer:

    public partial class resume_school
    {
        public static IQueryable<resume_school> Select(Guid resume_id)
        {
            DataClassesDataContext db = new DataClassesDataContext();

            IQueryable<resume_school> resume_schools = from rs in db.resume_schools
                                                       where rs.resume_id == resume_id
                                                       orderby rs.school.enddate descending
                                                       select rs;
            return resume_schools;
        }
       
        public static void Insertresume_school(resume_school newResumeSchool)
        {
            DataClassesDataContext db = new DataClassesDataContext();

            //newResumeSchool.resume_school_id = System.Guid.NewGuid();

            db.resume_schools.InsertOnSubmit(newResumeSchool);
            db.SubmitChanges();
        }

        public static void Deleteresume_school(resume_school oldResumeSchool)
        {
            DataClassesDataContext db = new DataClassesDataContext();

            db.resume_schools.Attach(oldResumeSchool);
            db.resume_schools.DeleteOnSubmit(oldResumeSchool);
            db.SubmitChanges();
        }

        public static void UpdateSchool(resume_school oldResumeSchool, resume_school newResumeSchool)
        {
            DataClassesDataContext db = new DataClassesDataContext();

            db.resume_schools.Attach(newResumeSchool, oldResumeSchool);
            db.SubmitChanges();
        }
    }

    Finally, here is a simple representation of the relevant entity objects:

    resume_school

         resume_school_id

         resume_id

         school_id

         version

    school

         school_id

         school1

         startdate

         enddate

         degree

         city

         state

         degree

         version

    resume_school and school have an association created via the school_id which represents a one to many relationship between school and resume_school.    school is a child of resume_school.

    Thanks in advance for any help you can provide!

    Saturday, April 2, 2011 12:19 AM

Answers

  • User3866881 posted

    In my opinion, Your "school" should be also a public property referring to another class, and you want to update through its public property called "startdate", isn't it?

    I'm afraid that you cannot do so, Update won't let you update a nested class.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 7, 2011 2:45 AM

All replies

  • User3866881 posted

    In my opinion, Your "school" should be also a public property referring to another class, and you want to update through its public property called "startdate", isn't it?

    I'm afraid that you cannot do so, Update won't let you update a nested class.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 7, 2011 2:45 AM
  • User180398699 posted

    Thanks for the reply.  Your understanding of what I'm attempting to accompolish is correct.  Do you have a recommendation for how I can proceed in a different direction?

    Thursday, April 7, 2011 10:23 AM
  • User3866881 posted

    In my opinion. I suggest you trying to split the two classes from each other by using GridView (One) - DetailsView(Many), with which you can do one-to-many inserting, deleting and updating.

    Thx

    http://www.aspdotnetcodes.com/Master_Child_GridView_DetailsView_Sample.aspx

    Friday, April 8, 2011 4:22 AM
  • User180398699 posted

    Not really sure that will work in this case.  This is all sitting in the context of a single resume that is displayed upon the page for view/edit.  At any given moment there is only one resume on the page, and these are the schools associated with that single resume.    That said, I appreciate the responses and will mark the first one as an answer. 

    Friday, April 8, 2011 7:26 AM