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

Rad Grid View Insertion with EDM Entities

13 Answers 152 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Wasif Jahangir
Top achievements
Rank 1
Wasif Jahangir asked on 02 Jun 2010, 06:56 AM
Hi,
  I need to do Insertion to RadGridView. when i give my ItemSource Sample objects like Collection of Person with two attributes, it insert.Edit/Delete them fine. but when i give my RadGridView new Object of EDM while Insertion i got Casting error i.e.

Unable to cast object of type 'Agility.Data.ProcurementRequestDetail' to type 'System.Data.Entity.DynamicProxies.ProcurementRequestDe_347B5DFCA18B3270199DC9CEB41ACCC807E270B79F7DB818FE4DD4F835F1D9AF
So do guide me how to Use RadGridView With EDM Entities.

Also this problem is occured when my Object is in Edit mode. but when my Object is new it works fine.

13 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 02 Jun 2010, 07:01 AM
Hi,

Can you post full stack trace? Please provide more info about your grid version as well.

Regards,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Wasif Jahangir
Top achievements
Rank 1
answered on 02 Jun 2010, 07:16 AM
Also this problem is occured when my Object is in Edit mode. but when my Object is new it works fine.

im at your latest version. i did Download/installed Telerik toolkit yesterday
here it is my stack trace with debugging hits:
Debugger:Breakpoint Hit: radGridView1_AddingNewDataItem, ProcurementRequest.xaml.cs line 199
A breakpoint was hit by the debugger.

Exception:Thrown: "Invalid property or field - 'Product' for type: Object" (System.ArgumentException)
A System.ArgumentException was thrown: "Invalid property or field - 'Product' for type: Object"

Exception:Caught: "Invalid property or field - 'Product' for type: Object" (System.ArgumentException)
A System.ArgumentException was caught: "Invalid property or field - 'Product' for type: Object"
..
.
.
.
.and same exceptions for all my other 3 types then
Debugger:Breakpoint Hit: InsertRadGridView_Click, ProcurementRequest.xaml.cs line 194
A breakpoint was hit by the debugger.
Exception:Thrown: "Unable to cast object of type 'Agility.Data.ProcurementRequestDetail' to type 'System.Data.Entity.DynamicProxies.ProcurementRequestDe_347B5DFCA18B3270199DC9CEB41ACCC807E270B79F7DB818FE4DD4F835F1D9AF'." (System.InvalidCastException)
A System.InvalidCastException was thrown: "Unable to cast object of type 'Agility.Data.ProcurementRequestDetail' to type 'System.Data.Entity.DynamicProxies.ProcurementRequestDe_347B5DFCA18B3270199DC9CEB41ACCC807E270B79F7DB818FE4DD4F835F1D9AF'."









0
Vlad
Telerik team
answered on 02 Jun 2010, 07:19 AM
Hello,

Can you post the code of radGridView1_AddingNewDataItem?

Kind regards,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Wasif Jahangir
Top achievements
Rank 1
answered on 02 Jun 2010, 07:49 AM
private void radGridView1_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
        {
            e.NewObject = new Data.ProcurementRequestDetail();
        } 
0
Wasif Jahangir
Top achievements
Rank 1
answered on 02 Jun 2010, 08:36 AM
what could be the issue. can u able to figure out..... ?
i dont know it is a very simple stuff. but not working.....

0
Vlad
Telerik team
answered on 02 Jun 2010, 09:10 AM
Hello,

Please bind the grid to CollectionView instead. Here is an example:

NorthwindEntities context = new NorthwindEntities();
RadGridView1.ItemsSource = CollectionViewSource.GetDefaultView(context.Products);

In this case you do not need to handle AddingNewDataItem - the grid will add the item automatically.

All the best,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Wasif Jahangir
Top achievements
Rank 1
answered on 02 Jun 2010, 09:18 AM
on page Load i gave
 radGridView1.ItemsSource = CollectionViewSource.GetDefaultView(procurementRequest.ProcurementRequestDetails);
but there is no AddNewButton Attached to Grid.
i have to explicitly my on button to call BeginInsert() method.

still prob is same. i m using it with EDM Entity. did cross check where u use this code with EDM Entity.
thanks



0
Wasif Jahangir
Top achievements
Rank 1
answered on 02 Jun 2010, 09:47 AM
did u able to figure out.....
i could not understand.if Telerik toolkit is not easy to use for simple operations then how much will they create problems for further usage.... ?
0
Vlad
Telerik team
answered on 02 Jun 2010, 10:16 AM
Hi,

I've just tested this however everything is working fine on my end. You can check the attached application for reference. Just press INSERT key and you will get new row in the grid.

Regards,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Wasif Jahangir
Top achievements
Rank 1
answered on 02 Jun 2010, 11:32 AM
kindly have a look at following attached file.
i m facing similar problem with EDM Entities....
even though CanInsertRow is True
here my code is like this:
List<person> lstPersons = new List<person>();
            lstPersons.Add(new person("wasif", "jahangir"));
            lstPersons.Add(new person("wasif", "jahangir"));
            lstPersons.Add(new person("wasif", "jahangir"));
            lstPersons.Add(new person("wasif", "jahangir"));
            lstPersons.Add(new person("wasif", "jahangir"));
            lstPersons.Add(new person("wasif", "jahangir"));

            radGridView1.ItemsSource = CollectionViewSource.GetDefaultView(lstPersons);







0
Wasif Jahangir
Top achievements
Rank 1
answered on 02 Jun 2010, 12:06 PM
i think im near to my solution
kindly ignore my last response
here my Collection i.e. {System.Data.Objects.DataClasses.EntityCollection<Agility.Data.ProcurementRequestDetail>}

but the EDM Default Namesapce is {System.Data.Objects.ObjectSet<WpfApplication1.Product>}

so what could be the possible reason either to convert or something else.
if to do casting then do guide me how to....?
thanks for ur prompt replies
0
Wasif Jahangir
Top achievements
Rank 1
answered on 02 Jun 2010, 01:43 PM
Your Solution is working fine.
however what i can figure out is we are using POCO Data Classes.
I Need to know what is SUPPORT for POCO Data classes withRadGridView control. im getting error Dynamic Proxy Casting while Insertion in DataGrid.
do refer me to any document which tell me about its support for POCO.
apparently i can figure out only this possible issue during insertion of my objects.

however need to know what is Suport for selfTracking Enitities/Lnq To SQL/WCF Data Services

0
Daniel Mettler
Top achievements
Rank 2
Iron
answered on 20 Oct 2021, 11:33 AM

We ran into the same issue with RadGrid having AutomaticInserts. After inserting an item it throw InvalidCastException: Unable to cast object of type 'MyDbModel.Role' to type 'System.Data.Entity.DynamicProxies.Role_...' in DataBind() at Rebind().

The issue was gone after I adapted the DataBinding to have an OrderBy().

Tags
GridView
Asked by
Wasif Jahangir
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Wasif Jahangir
Top achievements
Rank 1
Daniel Mettler
Top achievements
Rank 2
Iron
Share this question
or