Click here to Skip to main content
15,892,222 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Entity Framework : Clone an object and only its childs Pin
dilkonika12-Apr-15 11:32
dilkonika12-Apr-15 11:32 
GeneralRe: Entity Framework : Clone an object and only its childs Pin
Sascha Lefèvre12-Apr-15 11:40
professionalSascha Lefèvre12-Apr-15 11:40 
GeneralRe: Entity Framework : Clone an object and only its childs Pin
dilkonika12-Apr-15 11:38
dilkonika12-Apr-15 11:38 
GeneralRe: Entity Framework : Clone an object and only its childs Pin
Sascha Lefèvre12-Apr-15 12:09
professionalSascha Lefèvre12-Apr-15 12:09 
GeneralRe: Entity Framework : Clone an object and only its childs Pin
dilkonika12-Apr-15 13:26
dilkonika12-Apr-15 13:26 
GeneralRe: Entity Framework : Clone an object and only its childs Pin
Sascha Lefèvre12-Apr-15 14:39
professionalSascha Lefèvre12-Apr-15 14:39 
GeneralRe: Entity Framework : Clone an object and only its childs Pin
dilkonika12-Apr-15 15:05
dilkonika12-Apr-15 15:05 
GeneralRe: Entity Framework : Clone an object and only its childs Pin
Sascha Lefèvre12-Apr-15 23:18
professionalSascha Lefèvre12-Apr-15 23:18 
dilkonika wrote:
there are many articles on internet that suggest avoid ICloneable because of Shallow/Deep confusion.
Yes, I would also avoid it. The solution is to simply name your Clone-Method/Interface differently and let its name express what it does (shallow/deep/configurable).

Are you aware that the method CopyTo(..) makes a shallow copy and ignores fields? Basically the only advantage it has over Object.MemberwiseClone[^] is that you have the possibility to specify whether "parent" properties should be copied or not.
So if you call it on a Student, it will copy the reference to his Result(s), not make a copy of his Result(s).

dilkonika wrote:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Core.dll
Additional information: Collection was modified; enumeration operation may not execute.
I assume you used this code:
VB
newitm = New Myobject
currentobj.CopyTo(newitm, False)
context.MyObjects.Add(Newitm)
context.savechanges
in a foreach-loop where you iterated over objects (currentobj) in context? You can't modify a collection while you're iterating over it using an Enumerator (which is what a foreach-loop does). Your options:
- Iterate using a for-loop, if the source collection has an indexer, in reverse direction.
- Make a copy of the collection and iterate over this copy while modifying the source collection.
- Create a new collection of objects to be added/deleted while iterating the source collection. When finished, add/delete the objects contained in the new collection to/from the source collection.
GeneralRe: Entity Framework : Clone an object and only its childs Pin
dilkonika13-Apr-15 5:04
dilkonika13-Apr-15 5:04 
GeneralRe: Entity Framework : Clone an object and only its childs Pin
Sascha Lefèvre13-Apr-15 5:30
professionalSascha Lefèvre13-Apr-15 5:30 
QuestionEntity Framework : Why this extension is not usable ? Pin
dilkonika10-Apr-15 18:25
dilkonika10-Apr-15 18:25 
AnswerRe: Entity Framework : Why this extension is not usable ? Pin
Dave Kreskowiak10-Apr-15 19:56
mveDave Kreskowiak10-Apr-15 19:56 
GeneralRe: Entity Framework : Why this extension is not usable ? Pin
dilkonika10-Apr-15 20:03
dilkonika10-Apr-15 20:03 
GeneralRe: Entity Framework : Why this extension is not usable ? Pin
Dave Kreskowiak10-Apr-15 20:34
mveDave Kreskowiak10-Apr-15 20:34 
GeneralRe: Entity Framework : Why this extension is not usable ? Pin
dilkonika11-Apr-15 5:33
dilkonika11-Apr-15 5:33 
GeneralRe: Entity Framework : Why this extension is not usable ? Pin
Dave Kreskowiak11-Apr-15 7:00
mveDave Kreskowiak11-Apr-15 7:00 
GeneralRe: Entity Framework : Why this extension is not usable ? Pin
dilkonika11-Apr-15 7:34
dilkonika11-Apr-15 7:34 
GeneralRe: Entity Framework : Why this extension is not usable ? Pin
Dave Kreskowiak11-Apr-15 8:32
mveDave Kreskowiak11-Apr-15 8:32 
GeneralRe: Entity Framework : Why this extension is not usable ? Pin
dilkonika11-Apr-15 8:37
dilkonika11-Apr-15 8:37 
GeneralRe: Entity Framework : Why this extension is not usable ? Pin
Dave Kreskowiak12-Apr-15 5:04
mveDave Kreskowiak12-Apr-15 5:04 
GeneralRe: Entity Framework : Why this extension is not usable ? Pin
dilkonika12-Apr-15 17:58
dilkonika12-Apr-15 17:58 
GeneralRe: Entity Framework : Why this extension is not usable ? Pin
Dave Kreskowiak12-Apr-15 18:36
mveDave Kreskowiak12-Apr-15 18:36 
GeneralRe: Entity Framework : Why this extension is not usable ? Pin
dilkonika12-Apr-15 18:39
dilkonika12-Apr-15 18:39 
GeneralRe: Entity Framework : Why this extension is not usable ? Pin
Dave Kreskowiak13-Apr-15 2:57
mveDave Kreskowiak13-Apr-15 2:57 
GeneralRe: Entity Framework : Why this extension is not usable ? Pin
dilkonika13-Apr-15 5:08
dilkonika13-Apr-15 5:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.