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

[Solved] Problem in default delete with entity framework?

1 Answer 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
michelle
Top achievements
Rank 1
michelle asked on 07 Aug 2013, 07:29 PM
I used the telerik radgrid.  Not sure how to tell which version it is?  In Telerik.Web.UI property "version" the value is 2011.3.1115.35.  Runtime version is v2.0.50727.

I am using just the default delete (not my own code) against an entity framework datasource see below, but the delete gives an exception in my entity framework code..

Here is the code

 <asp:EntityDataSource ID="EntityDataSourceProducts" runat="server" ConnectionString="name=ApogeeCentralEntities" DefaultContainerName="ApogeeCentralEntities" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="Products" >
    </asp:EntityDataSource>


<telerik:RadGrid ID="gridSPCs"
                                  runat="server"
                                  AutoGenerateColumns="True"
                                  ShowGroupPanel="True"
                                  GridLines="None"
                                  AllowSorting="True"
     DataSourceID="EntityDataSourceProducts"
       AllowAutomaticDeletes="True"
       AllowAutomaticUpdates="True"
       AllowAutomaticInserts="True"
      
                                  AllowScroll = "True"
                                  Width="99.9%"
                                  AllowFilteringByColumn="True"
                                  AllowMultiRowSelection="True"
                                  EnableLinqExpressions="false"
                                  ItemStyle-VerticalAlign="Top"
                                  PageSize="25"
                                  AutoGenerateEditColumn="true"
                                  AutoGenerateDeleteColumn="true"
                                
                                  MasterTableView-ClientDataKeyNames="Id"
                                  GroupPanel-ForeColor="#cccccc"
                                  >
    
                                
                                <ClientSettings AllowGroupExpandCollapse="True" AllowDragToGroup="True" AllowColumnsReorder="true" ColumnsReorderMethod="Reorder" ReorderColumnsOnClient="true">
                                    <Animation AllowColumnReorderAnimation="true" ColumnReorderAnimationDuration="300" AllowColumnRevertAnimation="true" />
                                    <Selecting AllowRowSelect="true" />
                                    <Scrolling UseStaticHeaders="true" AllowScroll="true" ScrollHeight="400px" />
                                    <Resizing AllowColumnResize="true" ClipCellContentOnResize="false" EnableRealTimeResize="true" />
                                </ClientSettings>

                                <GroupingSettings ShowUnGroupButton="true" />
                                
                </telerik:RadGrid>


When I try to delete one of the rows, I get an exception in the entity designer code

The exception is..

The property 'Name' cannot be set to a null value.

Here is the code where the exception happens

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String Name
        {
            get
            {
                return _Name;
            }
            set
            {
                OnNameChanging(value);
                ReportPropertyChanging("Name");
                _Name = StructuralObject.SetValidValue(value, false, "Name");//this line gives exception
                ReportPropertyChanged("Name");
                OnNameChanged();
            }
        }

Edits are working fine, this is just on DELETE that I am getting this error!!  Any ideas?

Thanks for your help in advance!


By the way I just realized it only gives this error if the name is null in the data being deleted but still not sure why?  Why does it matter if the name is null if the row is just being deleted?

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 12 Aug 2013, 08:53 AM
Hello,

Most probably the problem comes from the fact that your Name property is mapped as IsNullable=false and since you want to pass a null value the delete operation throws an exception. Please try to set the column either as IsNullable=true or provide a value for that column prior deleting the record and you should not have problems.

If you need further assistance, please share your full page source code along with the code-behind file content. Thus all the people who want to help you will have better understanding of your case.

Regards,
Andrey
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
michelle
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or