1

I've an Entity Framework Layer and I've extended a class from that layer. The code is as follows:

public partial class FeatureMaster : EntityObject
{
    public string ParentFeatureName
    {
        get
        {
            return (from r in Global.dc.FeatureMasters
                    where r.FeatureId == FeatureParentId
                    select r).SingleOrDefault().FeatureName;
        }
        set
        {
            FeatureParentId = (from r in Global.dc.FeatureMasters
                               where r.FeatureName == value
                               select r).SingleOrDefault().FeatureId;
            ReportPropertyChanged(("ParentFeatureName"));
            ReportPropertyChanged(("FeatureParentId"));
        }
    }
}

Now I wish to use the same in my ASP.NET Page. The code for my ASP.NET Page is:

    <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="ListFeatureMaster.aspx.cs" Inherits="Backend.ListFeatureMaster" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMain" runat="server">
    <asp:GridView ID="grdRecords" runat="server" AllowPaging="True" AllowSorting="True"
        AutoGenerateColumns="False" DataKeyNames="FeatureId" DataSourceID="EntityDataSource1">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
            <asp:BoundField DataField="FeatureId" HeaderText="FeatureId" ReadOnly="True" SortExpression="FeatureId" />
            <asp:BoundField DataField="FeatureName" HeaderText="FeatureName" SortExpression="FeatureName" />
            <asp:BoundField DataField="FeatureParentId" HeaderText="FeatureParentId" SortExpression="FeatureParentId" />
            <asp:BoundField DataField="FeatureDescription" HeaderText="FeatureDescription" SortExpression="FeatureDescription" />
            <asp:TemplateField HeaderText="ParentFeatureName" SortExpression="ParentFeatureName">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="EntityDataSource1"
                        AppendDataBoundItems="true" DataTextField="ParentFeatureName" DataValueField="ParentFeatureName"
                        SelectedValue='<%# Bind("ParentFeatureName") %>'>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("ParentFeatureName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=BackendEntities"
        DefaultContainerName="BackendEntities" EnableFlattening="False" EntitySetName="FeatureMasters"
        EntityTypeFilter="FeatureMaster" EnableDelete="True" EnableUpdate="True">
    </asp:EntityDataSource>
        <asp:EntityDataSource ID="EntityDataSource2" runat="server" ConnectionString="name=BackendEntities"
        DefaultContainerName="BackendEntities" EnableFlattening="False" EntitySetName="FeatureMasters"
        EntityTypeFilter="FeatureMaster" EnableDelete="True" EnableUpdate="True">
    </asp:EntityDataSource>
</asp:Content>

The trouble is that when I execute this code, it works well on first load and navigation, but when I try to update the record, I get the error. Please help me to resolve the same.

Error message says:

A property named 'ParentFeatureName' was not found on the entity during an insert, update, or delete operation. Check to ensure that properties specified as binding expressions are available to the data source.

2 Answers 2

1

I think the problem is that you don't attach a custom property to your entity, and then save it. You can have a look Adding customer property to entity class

Hope it helps.

Sign up to request clarification or add additional context in comments.

1 Comment

@minhchat_vo - its not working and not helping me. Please suggest me some other alternative.
0

I got the solution.

I changed definition of GridView and added OnRowUpdating event to that. The ASPX Page code now looks like:

<asp:GridView ID="grdRecords" runat="server" AllowPaging="True" AllowSorting="True"
    AutoGenerateColumns="False" DataKeyNames="FeatureId" DataSourceID="EntityDataSource1" OnRowUpdating="grdRecords_RowUpdating">

In my .aspx.cs file, I added code for Event Handler. The code for the same looks as below:

        protected void grdRecords_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int primaryKey = Convert.ToInt32(grdRecords.DataKeys[e.RowIndex].Value);

        FeatureMaster existingRecord = Global.dc.FeatureMasters.First(r => r.FeatureId == primaryKey);
        existingRecord.FeatureName = e.NewValues["FeatureName"].ToString();
        existingRecord.ParentFeatureName = ((DropDownList)(grdRecords.Rows[e.RowIndex].FindControl("DropDownList1"))).SelectedValue.ToString();
        existingRecord.FeatureDescription = e.NewValues["FeatureDescription"].ToString();

        Global.dc.SaveChanges();

        grdRecords.EditIndex = -1;

        e.Cancel = true;
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.