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

Error when upgrade to silverlight 4

8 Answers 128 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Edo Cof
Top achievements
Rank 1
Edo Cof asked on 18 Mar 2010, 07:33 PM
I just install silverlight tools 4 for Visual studi 2010 RC and upgrade my project to Silverlight 4. I also download RadControls for Silverlight 4 RC (zip, 10723 KB)

On button click i call: radGrid.beginInsert() and here i get error:
An entity with the same identity already exists in this EntitySet.

My table is simple. Column ID (int - identitty) and Name (string).

I didn't get this before i upgrade project to S4.

Stack trace (if it helps):
   at System.ServiceModel.DomainServices.Client.EntitySet.AddInternal(Entity entity)
   at System.ServiceModel.DomainServices.Client.EntitySet.Add(Entity entity)
   at System.Windows.Controls.PagedEntityCollectionView.Add(Object item)
   at System.Windows.Controls.EntityCollectionView.AddNew()
   at System.Windows.Controls.DomainDataSourceView.System.ComponentModel.IEditableCollectionView.AddNew()
   at Telerik.Windows.Data.DataItemCollection.AddNew()
   at Telerik.Windows.Controls.GridView.EditContext.AddNew()
   at Telerik.Windows.Controls.GridView.GridViewDataControl.CreateNewItem()
   at Telerik.Windows.Controls.GridView.GridViewDataControl.ShowInsertRowIfNeeded()
   at Telerik.Windows.Controls.GridView.GridViewDataControl.BeginInsert()
   at Urnik.Tables.SifrantPage.buttonAddClick(Object sender, RoutedEventArgs e)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)

8 Answers, 1 is accepted

Sort by
0
Accepted
Stefan Dobrev
Telerik team
answered on 19 Mar 2010, 01:52 PM
Hi Matjaz Cof,

This problem comes from the fact that RIA Services have started to validate the entity's key on the client when the entity is added to the underlying entity set. What is happening in your case is that when the new object is created on the client its ID property is set to the default value of int - 0, but you already have an item with this ID in your collection and RIA services are throwing exception. The best way to solve this is to implement the partial method OnCreated() for your generated entity class in the Silverlight project. In this method you will set a unique ID for you new object. Here is a sample implementation for a Person entity object:
public partial class Person
{
    partial void OnCreated()
    {
        this.ID = -1;
    }
}


Hope this helps,
Stefan Dobrev
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
Edo Cof
Top achievements
Rank 1
answered on 20 Mar 2010, 10:39 AM
Thanks, it's not the perfect solution, because i have lot of tables. Maybe you would consider implement something into RadGrid.
0
Louis Bouchard
Top achievements
Rank 1
answered on 19 May 2010, 02:47 AM
Hello Stephan,

When you said "the partial method OnCreated() for your generated entity class in the Silverlight project", you mean that if I got a.edmx, so I have to  create OnCreated in the a.Designer.cs?

If not, where?

Thank you.
0
Stefan Dobrev
Telerik team
answered on 19 May 2010, 11:02 AM
Hello Louis,

This method is in your Silverlight project for the entities generated by RIA Services. The edmx file is on the server side and is used by Entity Framework. You have to do this on the client side in your Silverlight project.

Regards,
Stefan Dobrev
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
Louis Bouchard
Top achievements
Rank 1
answered on 19 May 2010, 04:26 PM
Hello Stephan,

Ok but I have created a Business Application and I don't see any class created by RIA on server side.  I will try to find something on the net about this issue. 

Thank you for your time dear Stephan.
0
Louis Bouchard
Top achievements
Rank 1
answered on 19 May 2010, 04:45 PM

It's working now.  I have to add at the end of my stored procedure this line :

 

SELECT

 

SCOPE_IDENTITY() as Id

And in the edmx file, right click on my entity and choose Stored Procedure Mapping.  In the Mapping Details (Parameter/Column section), under Result Column Bindings I specified Id -> <the name of my key field>

 

That's it.

0
Jonx
Top achievements
Rank 2
answered on 10 Dec 2010, 04:58 AM
Hello Stefan,

Thank you for the tip but it's strange that this is needed as the ID in my case is autogénérated on the server
normaly when the entity gets saved to the DB.

But  nonetheless it's nort working without your tips so thanks again...
John.
0
Shanmuga
Top achievements
Rank 1
answered on 26 Aug 2015, 10:42 AM

Hi Team,

var results = context.Infos.Where((Infos i) => loadOperation.Entities.Contains(i)).ToList();
results.ForEach((Infos i) => context.Infos.Detach(i)); ​

This my view model code. When i add new item in grid i got below error

"The specified entity is not contained in this EntitySet"

I just install silverlight tools ​5 for Visual studio 2010 and upgrade my project to Silverlight ​5. I also download Rad Controls for Silverlight ​5.

I didn't get this before i upgrade project to S5.

What mistake i did?.

 Pls Help me

Tags
GridView
Asked by
Edo Cof
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Edo Cof
Top achievements
Rank 1
Louis Bouchard
Top achievements
Rank 1
Jonx
Top achievements
Rank 2
Shanmuga
Top achievements
Rank 1
Share this question
or