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
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.
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.
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.
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.
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.
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.
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