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

Grid automatics update llblgen Entity Problem

1 Answer 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hans van Rijnswoud
Top achievements
Rank 2
Hans van Rijnswoud asked on 25 Aug 2009, 01:04 PM
Hi,

We use the telerik Q 2009 with llblgen pro as #1 O/R mapper and data-access tier generator for .NET.
I create a simple grid directly connected on the entity object via a asp:objectdatasource.

The method select and insert works fine.
But i have a problem with the update method and delete.

For the update and delete method i have the following :
49|error|500|The field 'Id' is read-only and can't be changed.|
If I enable the column Id i don't have any error but the item is not update but created.

I try also to use UpdateCommand Event and UpdateParameters but i received the same error.
Any experience with LLBLgen and Telerik ?

Thanks is advance for your help.

Edwin.


Bellow my code for the Grid :

<telerik:RadGrid ID="GridBranche" runat="server"  
    AutoGenerateColumns="false"  
    PageSize="20"  
    GridLines="None" 
    AllowPaging="true"  
    AllowAutomaticInserts="true"  
    AllowAutomaticUpdates="true"  
    AllowAutomaticDeletes="true" 
    DataSourceID="_objDataSource"  
    PagerStyle-AlwaysVisible="True" OnItemDeleted="GridBranche_OnItemDeleted"
    <PagerStyle Mode="Slider" /> 
    <MasterTableView EditMode="InPlace" CommandItemDisplay="Top" HorizontalAlign="NotSet" AutoGenerateColumns="false"  
    DataKeyNames="Id"
        <Columns> 
            <telerik:GridBoundColumn HeaderText="Id" DataField="Id" DataType="System.Int32"  
            SortExpression="Id" UniqueName="BrancheId" ReadOnly="true" /> 
            <telerik:GridBoundColumn HeaderText="Naam" DataField="Name" /> 
            <telerik:GridDropDownColumn HeaderText="Taal" DataField="LanguageId" DataSourceID="_objLanguageSource"  
            DataType="System.Int32" ListValueField="Id" ListTextField="Name" SortExpression="Id" UniqueName="Languages">             
            </telerik:GridDropDownColumn> 
            <telerik:GridDropDownColumn HeaderText="Land" DataField="CountryId" DataSourceID="_objCountrySource"  
            DataType="System.Int32" ListValueField="Id" ListTextField="Name" SortExpression="Id" UniqueName="Country"
            </telerik:GridDropDownColumn>             
            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" HeaderText="Bewerken" /> 
            <telerik:GridButtonColumn ConfirmText="Delete this branche?" ConfirmDialogType="RadWindow" 
                        ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete" 
                        UniqueName="DeleteColumn" HeaderText="Wissen" /> 
        </Columns> 
        <EditFormSettings ColumnNumber="3" CaptionDataField="Name" CaptionFormatString="Aanpassen branche: {0}"
            <FormTableItemStyle Wrap="false" /> 
            <FormMainTableStyle GridLines="None" CellPadding="3" BackColor="White" Width="100%" /> 
            <FormTableStyle CellSpacing="0" CellPadding="2" Height="110px" BackColor="White" /> 
            <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle> 
            <EditColumn ButtonType="ImageButton"  
                InsertText="Insert banner type" UpdateText="Update banner type" UniqueName="EditCommandColumn1" CancelText="Cancel edit"
            </EditColumn> 
        </EditFormSettings> 
    </MasterTableView> 
</telerik:RadGrid> 
 
<asp:ObjectDataSource ID="_objDataSource" runat="server" 
    InsertMethod="SaveBranche"  
    SelectMethod="GetBranchesForOverview"  
    UpdateMethod="SaveBranche"  
    DeleteMethod="DeleteBranche" 
    TypeName="Adver.Service.Domain.BranchesService"  
    DataObjectTypeName="Adver.Business.EntityClasses.BranchesEntity">    
</asp:ObjectDataSource> 
 
<asp:ObjectDataSource ID="_objLanguageSource" runat="server" SelectMethod="GetLanguages"  
TypeName="Adver.Service.Domain.LanguageService"
</asp:ObjectDataSource> 
 
 
<asp:ObjectDataSource ID="_objCountrySource" runat="server" SelectMethod="GetCountries"  
TypeName="Adver.Service.Domain.CountryService"
</asp:ObjectDataSource> 


code for the service layer

public bool  SaveBranche(BranchesEntity entity) 
        { 
            if(entity.Id > 0) 
            { 
                entity.IsNew = true
            } 
            return repository.SaveBranche(entity); 
        } 
 
        public bool UpdateBranche(BranchesEntity entity, int id) 
        { 
            entity.Fields[(int)BranchesFieldIndex.Id].ForcedCurrentValueWrite(id); 
            entity.IsNew = false
            return repository.SaveBranche(entity); 
        } 




1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 27 Aug 2009, 12:53 PM
Hi Edwin,

The error you have described is caused by the ObjectDataSource and is not related to RadGrid control (you may observe same behavior with GridView control).
When datasource is updating, it is trying to create a new instance of the entity and set its properties. However as the primary key's property is read only and cannot be modified, the LLBLGen is throwing an exception. In order to workaround this you may try to expose an update method which takes entity's properties' values as parameters and build the entity in the method's body before updating it.

Regards,
Rosen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Hans van Rijnswoud
Top achievements
Rank 2
Answers by
Rosen
Telerik team
Share this question
or