c# - Why do I need to perform a deep clone to get this code to work? -
The following code works, however, it works because I am finally creating deep clones of suppliers. If I do not do a deep clone, then we know that the supplier items have changed and the attempt to amend the supplier table has failed. This only occurs when the following line runs: I think this error is being changed about being archived. If you create a clone, then the collection you are enumerating is not allowed to focus (or anything that calculates an IEnumerable). Being separated from the collection is being affected. Have you tried a shallow copy? I think this will work fine. A shallow copy can be made with ToArray. foreach (Suppliers Suppliers in Exceptions) . Strangely, this also happens when
delete () is executed. Why does this happen I have posted the following working code for your inspection. As I say, if you try to loop without deep cloning then it does not work ... any thoughts? Public Zero Deleted Slippers (ILIIT & Lt; Supplier & Suppliers; Suppliers, IT 32 Parent ID) {// If a supplier has been removed from the format, then we have to remove from the database. . // Get a Supplier from the database list & lt; Supplier & gt; DbSuppliers = Supplier. FindAllByParentID (parentID); // Return any such supplier who are in the database which are no longer on this form. Inumable & lt; Supplier & gt; Results = dbSuppliers.Where (f =>! Suppliers.Any (D => DID == f.Id)); IList & LT; Supplier & gt; Exception = null; // code guard if (result! = Null) {// cast as a list of IList & lt; Supplier & gt; TempList = (ILIIT & Lt; Supplier & gt;) results.ToList (); // deep clone otherwise there will be an error exception = (ILIST
Comments
Post a Comment