Error when upgrade to silverlight 4

9 posts, 1 answers
  1. Edo Cof
    Edo Cof avatar
    47 posts
    Member since:
    Feb 2006

    Posted 18 Mar 2010 Link to this post

    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)
  2. Answer
    Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 19 Mar 2010 Link to this post

    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.
  3. DevCraft banner
  4. Edo Cof
    Edo Cof avatar
    47 posts
    Member since:
    Feb 2006

    Posted 20 Mar 2010 Link to this post

    Thanks, it's not the perfect solution, because i have lot of tables. Maybe you would consider implement something into RadGrid.
  5. Louis Bouchard
    Louis Bouchard avatar
    94 posts
    Member since:
    Feb 2010

    Posted 18 May 2010 Link to this post

    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.
  6. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 19 May 2010 Link to this post

    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.
  7. Louis Bouchard
    Louis Bouchard avatar
    94 posts
    Member since:
    Feb 2010

    Posted 19 May 2010 Link to this post

    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.
  8. Louis Bouchard
    Louis Bouchard avatar
    94 posts
    Member since:
    Feb 2010

    Posted 19 May 2010 Link to this post

    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.

  9. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 09 Dec 2010 Link to this post

    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.
  10. Shanmuga
    Shanmuga avatar
    15 posts
    Member since:
    Mar 2015

    Posted 26 Aug 2015 in reply to Stefan Dobrev Link to this post

    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

Back to Top
DevCraft banner