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

Error on CancelNew

3 Answers 12 Views
DomainDataSource
This is a migrated thread and some comments may be shown as answers.
Heiko
Top achievements
Rank 1
Veteran
Heiko asked on 10 Sep 2012, 04:37 PM
In my application using QDSCV I simply add a new entity via "AddNew(...)". If the user cancels this adding operation I call "CancelNew()" which leads to an error.
I investigated the error a little bit and found out that in "DomainServiceCollection" the "OnCollectionChanged" event is triggered trying to remove the item from the EntitySet, But: the item has never been added to the underlying EntitySet. When adding items the same "OnCollectionChanged" event is called and it tries to add the new item to the EntitySet. Unfortunately it is checking for "EntityState.Detached" instead of "EntityState.New" which is the EntityState the newly added item is in. Thus it is NOT in the EntitySet and the remove operation later on crashes.

foreach (TEntity item in e.NewItems)
{
    if (item.EntityState == EntityState.Detached)
    {
        entitySet.Add(item);
    }
    this.totalItemCount++;
}

Also in my opinion the line "totalItemCount++" belongs in between the brackets under the Add-statement - why should the totalItemCount be increased if not item has been added to the entitySet?

Regards
Neils

3 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 13 Sep 2012, 02:22 PM
Hi,

I've tried to reproduce the reported exception, unfortunately to no avail.
I'm attaching my sample application for a reference. Could you please tell me how to simulate the error?
Thank you in advance.

P.S. The sample application requires SQLEXPRESS with Northwind installed (or you could change the connection string, but please use Northwind or AdventureWork databases or you will have to send me your database).

Kind regards,
Nedyalko Nikolov
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Heiko
Top achievements
Rank 1
Veteran
answered on 17 Sep 2012, 10:51 AM
Good morning!

I checked your example and indeed the entities state is "Detached" so no problem occurs. Here is my code:

EmailAddress email = new EmailAddress();
email.Person = this.CurrentPerson;
email.MailAddressType = MailAddressTypes.FirstOrDefault();
email.PreferredFlag = (!Mails.Any());
Mails.AddNew(email);

As soon as I set the MailAddressType the entities state changes from "Detached" to "New" so this causes the error later on (where the entity is not added to the internal EntitySet). WCF RIA Services has one more state "New" which the normal System.Data Enumeration has not. I can't tell you why the state changes but it seems this is how WCF RIA Services is working.

System.ServiceModel.DomainServices.Client.EntityState
    Deleted: Deleted
    Detached: Detached
    Modified: Modified
    New: New
    Unmodified: Unmodified


Regards
Neils
0
Nedyalko Nikolov
Telerik team
answered on 18 Sep 2012, 01:31 PM
Hi,

Could you send me a sample application which I can debug on my side in order to see what is going on?
Thank you in advance.

Greetings,
Nedyalko Nikolov
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

Tags
DomainDataSource
Asked by
Heiko
Top achievements
Rank 1
Veteran
Answers by
Nedyalko Nikolov
Telerik team
Heiko
Top achievements
Rank 1
Veteran
Share this question
or