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

Visual Basic

 
AnswerRe: Entity Framework : Clone an object and only its childs Pin
Sascha Lefèvre11-Apr-15 21:02
professionalSascha Lefèvre11-Apr-15 21:02 
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 
Yes now I have read this example. But as I see he implement the Icloneable.
there are many articles on internet that suggest avoid ICloneable because of Shallow/Deep confusion.

instead , I found another way :
<pre>  <Extension> _
    Public Sub CopyTo(Of T)(copyFrom As T, copyTo__1 As T, copyParentProperties As Boolean)
        Dim props As PropertyInfo()
        If copyParentProperties Then
            props = GetType(T).GetProperties()
        Else
            props = GetType(T).GetProperties(BindingFlags.[Public] Or BindingFlags.Instance Or BindingFlags.DeclaredOnly)
        End If
        Dim i As Integer = 0
        While i < props.Length
            Dim propertyValue = copyFrom.[GetType]().GetProperty(props(i).Name).GetValue(copyFrom, Nothing)
            copyTo__1.[GetType]().GetProperty(props(i).Name).SetValue(copyTo__1, propertyValue, Nothing)
            System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
        End While
    End Sub

But when I try to use it like this :
VB
newitm = New Myobject
currentobj.CopyTo(newitm, False)
context.MyObjects.Add(Newitm)
context.savechanges

I get an error on the line context.MyObjects.Add(Newitm):
CSS
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Core.dll

Additional information: Collection was modified; enumeration operation may not execute.

(But of course , if i create a new object and fill the properties manually one by one , the ADD method works without problems. )

What may be the problem ?
Thank you !
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 
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 

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.