This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, I've a problem when i try to modify an eager loaded collection. i've the entity Ensayo that have a EnsayoParametros collection. the problem is that when i try to modify the EnsayoParametros Colection it throws an exception. when i clear the collection nothing happend but when i try to add another collection to the entity it throws the exception. the code i'm trying to use is: using (EnsayoManager emgr = new EnsayoManager()) the exception is: "Collection was modified; enumeration operation may not execute." and the stack trace is: " at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)\r\n at System.Collections.Generic.List`1.Enumerator.MoveNextRare()\r\n at System.Collections.Generic.List`1.Enumerator.MoveNext()\r\n at Mindscape.LightSpeed.EntityCollection`1.AddRange(IEnumerable`1 collection)\r\n at dcf001.parametrizacion.btnSobreescribir_Click(Object sender, RoutedEventArgs e) in E:\\wdir\\pcb\\project\\PCB\\PCB\\parametrizacion.xaml.cs:line 151"
thanks
ariel |
|
|
Hmm, the only thing I can see that would cause this is if EnsayoTable and mEnsayo are the same object -- this would mean that they have the same EnsayoParametros collection, which would mean that iterating over that collection adding items would modify the collection while it was being iterated. However it is hard to be sure from this code fragment. (It's possible there might be some WPF data binding stuff that's also affecting the collection, for example.) Could you create a project (ideally a small console application) which reproduces the problem so we can have a look at it? You can attach a zip file via the Options tab, or email it to us via the contact form (please strip out all binaries first). Thanks! |
|
|
thanks for your attention ivan. i've resolved the problem with this code:
using (EnsayoManager emgr = new EnsayoManager())
thanks
Ariel |
|
|
ivanì've another poprblem now. i've set a foreign key as restrict and i've set the is dependent property in true. but when i try to delete an entity that have a parent row it don`t throw an exception when i need it. How can i do to obtain this exception and that mindscape do not delete this entity because it have parents? if u try to delete this entity from the mysql browser i can't delete it and throws this message: "Cannot delete or update a parent row: a foreign key constraint fails (`pcb_div/ensayoparametro`, CONSTRAINT `FK_EnsayoParametro_Ensayo_EnsayoId` FOREIGN KEY (`EnsayoId`) REFERENCES `ensayo` (`Id`))"
but whne i'try using mindscape it delete the collection of EnsayoParametros and the Ensayo
thanks
ariel |
|
|
If you delete a parent entity, with dependent child entities, then the dependent child entities are also deleted. (If the child entities are not dependent, their parent is set to null.) This is by design. It sounds like you want LightSpeed to refuse to delete the parent as long as it has any children, so that you have to explicitly delete all the children before you can delete the parent. This is not provided within the framework, but you can easily create it at the application level: partial class Ensayo { |
|
|
you`re right Ivan.
I haven't realized about that!! Thanks Ariel |
|
|
Ivan you've said to me that if i set the is dependient property to null then when i delete an entity that have a collection, the children of this entity are not going to be deleted, so the foreign key will be null. But i'm trying to do that and all che children are being deleted. How can i do to reswolve this? thanks |
|
|
You need to set the relationship to be nullable (if you're using the designer) or the foreign key field to be nullable (e.g. int? _ensayoId rather than int _ensayoId) (if you're writing classes by hand). If you're still seeing child deletion behaviour, please post the relevant classes (C# or VB code, no need for the .lsmodel) and the associated SQL CREATE TABLE statements and we'll take a look. You can attach a zip file via the Options tab (if the content is sensitive, you can email via the contact form). Thanks! |
|