Skip to main content

A primary key field specified using the KeyFieldName property is not found

Error Description:

The error can occur when you use the following extensions:

Solution:

Check whether the KeyFieldName property is specified if you use the following GridView features:

  • Editing.
  • Selection.
  • Master Detail.
  • Endless Paging.

Try one of the following suggestions to overcome this issue:

  1. A data source does not contain a field specified in the KeyFieldName property. Make sure the field name is spelled correctly and in the correct case.

  2. The field is not marked with the “public” keyword or does not have “get”/“set” accessors. You should implement the “get”/“set” accessors for the fields/properties you use;

  3. The data source fields were changed and do not contain this field. You should update the KeyFieldName property to reflect the changes made to the data source.

  4. The data source does not contain data records, and the GridView cannot map the schema of data records. Handle the GridViewSettings.DataBinding event and specify the data record type (MVCxGridView.ForceDataRowType).

    @Html.DevExpress().GridView(settings => {
        settings.DataBinding = (send, evargs) => {
            MVCxGridView grid = send as MVCxGridView;
            grid.ForceDataRowType(typeof(DATA_RECORD_TYPE_HERE));
        };
    }).BindToEF()
    
  5. The GridView extension is incorrectly bound to its data source. See also: Bind Grid View to Data at Runtime.

  6. Set the EnableRowsCache property to false.