views:

334

answers:

1

Hi,

I have a TreeNode class with Expression. Expression has Parameter ID pointing to Parameters table. Each parameter has ParameterGroupId.

I have a Copy& paste TreeNode feature. When I copy an existing node, I create a new node but using the same reference to the P (Parameter) and PG (ParameterGroup).

The problem is, the new node was added to the context but I haven’t pasted it yet. So if I Save now, it will be added to the DB with Parent NULL. In some cases, I might copy another node and thus running over the previous one so I don’t want it to be saved before time.

If I don’t use the same P reference and just create a new one with just the ID like in http://blogs.msdn.com/alexj/archive/2009/04/22/tip-14-caching-entity-framework-reference-data.aspx and use AttachTo(), it tries to save the cloned P and PG as if it they were new. It even fails since some of the fields are mandatory.

In short, I want to be able to save the cloned object but not the referenced data.

This is the copy ctor for Expression

public Expression(Expression copyFrom) {
    if (copyFrom != null ) {
        this .Parameter = new Parameter () {
            ID = copyFrom.Parameter.ID,
            ParameterGroup = new ParameterGroup {
                ID = copyFrom.Parameter.ParameterGroup.ID }
        };
    }
}

The pasting goes like this:

private void PasteNode(TreeNode copyToNode Node ) {
    m_Tree.Paste( clipBoardNode, copyToNode Node);
    context.AttachTo("ParameterSet", clipBoardNode.Expression.Parameter);
}
A: 

Someone? Still stuck on that issue

Avi Harush