1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
Dim test As New Produit
Using entites As IRepository(Of Produit) = ModelFactory(Of Produit).CreateManager
//je recupère la donnée
Dim read = entites.Read(myId)
//je clone l'enregistrement
test = Clone(Of Produit)(read)
//je détache du modèle
entites.Detach(read)
test.EntityKey = Nothing
test.ID = Nothing
//je l'insert et la sauve
entites.Create(test)
entites.Save()
End Using
End Sub
//fonction qui serialise et prepare le clonde
Public Shared Function Clone(Of t)(source As IEntity) As t
Dim obj = New DataContractSerializer(GetType(t))
Using stream = New System.IO.MemoryStream()
obj.WriteObject(stream, source)
stream.Seek(0, System.IO.SeekOrigin.Begin)
Return DirectCast(obj.ReadObject(stream), t)
End Using
End Function |