Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Clone of the object
Message
 
 
To
All
General information
Forum:
ASP.NET
Category:
Entity Framework
Title:
Clone of the object
Environment versions
Environment:
C# 5.0
OS:
Windows 10
Database:
MS SQL Server
Miscellaneous
Thread ID:
01661186
Message ID:
01661186
Views:
47
UPDATE2. Eventually I solved the problem by just setting all navigation properties to null for the lineItem.


UPDATE. Went ahead and implemented the Clone method in the partial class of my model. I wish the Reversed POCO generator had this method already, although we can probably add it as well.

For now I just did it for a particular class where I needed it. Will test now.

Hi everybody,

This is the continuation of my previous question. I think I need to create a copy of the line item in order to add it to the duplicated purchase order. I did some search in stackoverflow and found few blogs on the topic one of them being by Rick Strahl

https://weblog.west-wind.com/posts/2009/Aug/04/Simplistic-Object-Copying-in-NET

and the other is https://actualrandy.wordpress.com/2015/01/17/copying-with-automapper-and-memberwiseclone/

So, in my code I'm now trying:
foreach(IPchord lineItem in purchaseOrdersViewModel.LineItems)
                {
                    IPchord newLineItem = lineItem.MemberwiseClone();
but this produces an error in compile time:

cannot access protected member via a qualifier ...

So, I'm not sure how should I proceed here. I want a copy of that object (only simple properties).

Thanks a lot in advance.
If it's not broken, fix it until it is.


My Blog
Reply
Map
View

Click here to load this message in the networking platform