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

LINQ to SQL will not update on grids

9 Answers 182 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 22 Sep 2008, 06:48 PM
Hey all,

I made a post a few days ago, but didn't get much help at all other than a hyperlink to a project that is not implemented the same way as my own. So I decided to speak to another company I know which makes use of the Telerik controls, and low and behold they told me they also found this problem with the controls and now avoid using LINQ Datasources with Telerik, as it just does not work, however regular SQL Datasources work without a problem.

Surely this is not a bug, as it's quite a major feature? Once again, I will include what my code currently looks like, and I would appreciate it if somebody actually read my code to try notice the problem, rather than pasting a hyperlink to a project that is not implementing the same methods (thus proving un-helpful).

If I don't get a solution from this, I'll be raising this to the bug support ticket system (which I would rather avoid, as this surely cannot be a bug).

Regards,
Justin

<asp:LinqDataSource ID="LinqDataSource1" runat="server"   
                            ContextTypeName="db_vmmDataContext"   
                            Select="new (ServiceDate, ServicedBy, InvoiceNo, Mileage, ServiceType, DateTyresLastPurchased, NextServiceDueMiles, NextServiceDueDt, MOTd, WhatWasDone, ServiceHistoryID)"   
                            TableName="vmm_ServiceHistories" Where="VehicleID == @VehicleID">  
                        <whereparameters> 
                            <asp:ControlParameter ControlID="lstVehicleSelectByReg" Name="VehicleID"   
                            PropertyName="SelectedValue" Type="Int32" /> 
                        </whereparameters> 
                        </asp:LinqDataSource> 
                        <div> 
                            <telerik:RadGrid ID="rpt_ServiceHistory" runat="server" AllowAutomaticDeletes="True"   
                                AllowAutomaticUpdates="True" AutoGenerateColumns="False"   
                                DataSourceID="LinqDataSource1" GridLines="None" Skin="Hay"   
                                onupdatecommand="rpt_ServiceHistory_UpdateCommand">  
                                <mastertableview datasourceid="LinqDataSource1" EditMode="InPlace">  
                                    <rowindicatorcolumn> 
                                        <HeaderStyle Width="20px" /> 
                                    </rowindicatorcolumn> 
                                    <expandcollapsecolumn> 
                                        <HeaderStyle Width="20px" /> 
                                    </expandcollapsecolumn> 
                              
                                    <Columns> 
                                        <telerik:GridButtonColumn CommandName="Delete" Text="Delete"   
                                            UniqueName="column">  
                                        </telerik:GridButtonColumn> 
                                        <telerik:GridEditCommandColumn> 
                                        </telerik:GridEditCommandColumn> 
                                        <telerik:GridBoundColumn DataField="ServiceDate" DataType="System.DateTime"   
                                            HeaderText="Service Date" SortExpression="ServiceDate"   
                                            UniqueName="ServiceDate">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="ServicedBy" HeaderText="Serviced By"   
                                            SortExpression="ServicedBy" UniqueName="ServicedBy">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="InvoiceNo" DataType="System.Int32"   
                                            HeaderText="Invoice No" SortExpression="InvoiceNo" UniqueName="InvoiceNo">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="Mileage" DataType="System.Int32"   
                                            HeaderText="Mileage" SortExpression="Mileage" UniqueName="Mileage">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="ServiceType" HeaderText="Service Type"   
                                            SortExpression="ServiceType" UniqueName="ServiceType">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="DateTyresLastPurchased"   
                                            DataType="System.DateTime" HeaderText="Date Tyres Last Purchased"   
                                            SortExpression="DateTyresLastPurchased"   
                                            UniqueName="DateTyresLastPurchased">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="NextServiceDueMiles"   
                                            HeaderText="Next Service Due Miles" SortExpression="NextServiceDueMiles"   
                                            UniqueName="NextServiceDueMiles">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="NextServiceDueDt"   
                                            DataType="System.DateTime" HeaderText="Next Service Due Dt"   
                                            SortExpression="NextServiceDueDt" UniqueName="NextServiceDueDt">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridCheckBoxColumn DataField="MOTd" DataType="System.Boolean"   
                                            HeaderText="MOTd?" SortExpression="MOTd" UniqueName="MOTd">  
                                        </telerik:GridCheckBoxColumn> 
                                        <telerik:GridBoundColumn DataField="WhatWasDone" HeaderText="Wha tWas Done?"   
                                            SortExpression="WhatWasDone" UniqueName="WhatWasDone">  
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="ServiceHistoryID" DataType="System.Int32"   
                                            HeaderText="Service History ID" ReadOnly="True"   
                                            SortExpression="ServiceHistoryID" UniqueName="ServiceHistoryID"   
                                            Display="False">  
                                        </telerik:GridBoundColumn> 
                                    </Columns> 
                              
                              
                              
                                    <editformsettings> 
                                        <editcolumn uniquename="EditCommandColumn1">  
                                        </editcolumn> 
                                    </editformsettings> 
                              
                              
                              
                                </mastertableview> 
                                <filtermenu enabletheming="True">  
                                    <collapseanimation duration="200" type="OutQuint" /> 
                                </filtermenu> 
                            </telerik:RadGrid> 
                        </div> 

9 Answers, 1 is accepted

Sort by
0
PureCode
Top achievements
Rank 2
answered on 22 Sep 2008, 08:04 PM
Justin,

Just as a test, I setup one of the grids in my application to work like yours, and it worked. So, I had to look a bit deeper and found the following.

This is your LinqDataSource (with a bit more readable formatting):

<asp:LinqDataSource ID="LinqDataSource1" runat="server" 
    ContextTypeName="db_vmmDataContext"    
    Select="new (ServiceDate, ServicedBy, InvoiceNo, 
        Mileage, ServiceType, DateTyresLastPurchased, 
        NextServiceDueMiles, NextServiceDueDt, MOTd, 
        WhatWasDone, ServiceHistoryID)"    
    TableName="vmm_ServiceHistories" 
    Where="VehicleID == @VehicleID">   
    <whereparameters>  
        <asp:ControlParameter  
            ControlID="lstVehicleSelectByReg" 
            Name="VehicleID"    
            PropertyName="SelectedValue" 
            Type="Int32" />  
    </whereparameters>  
</asp:LinqDataSource> 

This is the original that VS2008 generated when I reconfigured my LinqDataSource (again, with more readable formatting):

<asp:LinqDataSource ID="ProductsLinqDataSource" runat="server"  
    ContextTypeName="Intranet.Database.IntranetDataContext" 
    Select="new (ID, Product_ID, Addition_Date, Name, 
        Description, Price, OrderDetails, Image_Name, 
        DiscontinueDate, Discontinued, Cost)"  
    TableName="Products"  
    Where="Product_ID == @Product_ID"
    <WhereParameters> 
        <asp:ControlParameter  
            ControlID="TestComboBox" 
            Name="Product_ID"  
            PropertyName="SelectedValue" 
            Type="Int32" /> 
    </WhereParameters> 
</asp:LinqDataSource> 

Looks very similar to yours but bombs out the application with the following error:

System.InvalidCastException: Unable to cast object of type 'DynamicClass1' to type 'Intranet.Database.Product'. 

I haven't got any idea what that MEANS, but I managed to get it to work by configuring my LinqDataSource as follows (formatting... yada yada):

<asp:LinqDataSource ID="ProductsLinqDataSource" runat="server"  
    ContextTypeName="Intranet.Database.IntranetDataContext" 
    TableName="Products"  
    Where="Product_ID == @Product_ID"
    <WhereParameters> 
        <asp:ControlParameter 
            ControlID="TestComboBox" 
            Name="Product_ID"  
            PropertyName="SelectedValue" 
            Type="Int32" /> 
    </WhereParameters> 
</asp:LinqDataSource> 

Note the difference, the SELECT is gone. Basically, it just does a 'SELECT * FROM <table>' now, and this works great. I think RadGrid may have issues with the 'new(<list of fieldnames>)' bit.

So, try removing that SELECT from your code, and see if that helps any as that works fine within my (very large) application.

Oh, also, your combo box will have to postback in order for the RadGrid to get updated. I use the AjaxManager for these things, so I am not sure if the combo box you have automatically posts back or causes validation (which refresh the page and as thus update the RadGrid).

Regards,

Mike


0
Justin
Top achievements
Rank 1
answered on 23 Sep 2008, 09:35 PM
Hi Mike,$0$0$0$0Thank you for taking the time to actually read my question, however your solution didn't solve the issue (although it did make a bit of sense!).$0$0$0$0$0As for the combo-box, that has auto-postback enabled, and works fine, updates the grid with all the correct data, the only issue is the update feature in the radgrid does nothing. Out of curiosity, what settings did you have on your grid? I'm curious if this issue is now down to a missing setting, or perhaps my control needs to be ajax enabled, as the controls I have installed are the ASP.NET AJAX Controls (however I never would of thought they would work one way and not the other...).$0$0$0$0$0Regards,$0$0Justin$0
0
Justin
Top achievements
Rank 1
answered on 23 Sep 2008, 10:12 PM
Also just noticed the "ItemUpdated" is not being fired, is that an issue?
0
PureCode
Top achievements
Rank 2
answered on 24 Sep 2008, 12:44 AM
Hey Justin,

the only additional things I have in my LinqDataSources are:

EnableInsert="True"  
EnableUpdate="True" 

These are set through Visual Studio 2008 in the LinqDataSource (under the 'advanced' button). There is also an 'EnableDelete', but I do not use that one.

I have the RadGrids themselves setup with the automatic insert, update and delete properties set to 'false'. For the rest they are pretty much default apart from columns, pager, filter, etc. DataSource-wise they are just set directly to the LinqDataSources and it works.

I do not use ItemUpdated (I use the events of the LinqDataSources themselves to detect updates and inserts), but I remember trying to use it without it ever firing, even on a successful update.

Regards,

Mike


0
Justin
Top achievements
Rank 1
answered on 24 Sep 2008, 09:43 PM
Hi Mike,

Still nothing, and I've run out of ideas. I've attached the aspx and cs file for the page in question, the grid in question is the only one attached to a linq data source (the rest are populated via the cs file). If you can't see anything, I think I'm going to open a support ticket with the telerik guys, as this is seriously confusing.

Regards,
Justin
0
PureCode
Top achievements
Rank 2
answered on 25 Sep 2008, 12:17 AM
Hmm,

I don't really see anything out of the ordinary in your aspx file to be honest (although I wonder why there is so much CSS stuff in there, especially the Telerik ones).

Only thing I can really think of is to move the LinqDataSource out of your tabs/multipage bit and stick it on the page itself.

Most of my grids have an expand/collapse column that will open to a tabs/multipage with more grids, and those update fine in there but I do have the LinqDataSources right on the page, not inside the tabs/multipages.

I will see if I can throw something similar together tonight and see what it does as it is a pain in the rear to change up my application for testing.

Regards,

Mike
0
Justin
Top achievements
Rank 1
answered on 26 Sep 2008, 10:25 AM
Hi Mike,$0$0$0$0I moved it to the top of the page (after the body tad, before the form tag), and it's giving the exactly same results. Should I just go ahead and open a support ticket, as this looks like it's a bug to me?$0$0$0$0$0Regards,$0$0Justin$0
0
PureCode
Top achievements
Rank 2
answered on 26 Sep 2008, 08:23 PM
Hey Justin,

Seems like an odd bug to me if it works great in my application (across many grids) and not for you.

I'll see into throwing a real small app together later today as I finally will have some time to do so. Just a database, grid and LinqDataSource. If that works here, then it should work for you right? If not, then there is something odd going on.

I'll get on that in a few hours.

Regards,

Mike
0
Vlad
Telerik team
answered on 07 Nov 2008, 09:05 AM
Hello Justin,

I just saw this thread and I notice that you missed to specify DataKeyNames for MasterTableView plus you do not have EnableDelete="True" and EnableUpdate="True" for this LinqDataSource. On the other hand LinqDataSource cannot apply automatic operations when you have specified Select property (projection). You need to do manual updates in this case or remove the Select declaration.

Greetings,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Justin
Top achievements
Rank 1
Answers by
PureCode
Top achievements
Rank 2
Justin
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or