copy an entity

Posts   
 
    
mafti23
User
Posts: 13
Joined: 12-Jun-2006
# Posted on: 03-Jul-2006 11:58:42   

Hi there,

i'm trying to copy an entity real easy, but i get message "id is readonly" this is my code.

        TopicCollection tc = new TopicCollection();
        IPredicateExpression filter = new PredicateExpression();

        filter.Add(PredicateFactory.CompareValue(TopicFieldIndex.QuestionnaireId,
                        ComparisonOperator.Equal, oldQuestionnaireID));

        tc.GetMulti(filter);
        foreach (TopicEntity te in tc)
        {
            te.IsNew = true;
            //remove old id
            te.SetNewFieldValue((int)TopicFieldIndex.Id, null);
            //update questionnaireID
            te.QuestionnaireId = newQuestionnaireID;
        }
        tc.SaveMulti();

will this be possibleif a tweak soimething, or do i really have to "copy" all fields into a new entity? btw id is the primary-key

edit: it works as long i set only IsNew however all the other fields are null, besides QuestionnaireID. because i set it to, Isnew, the other fields are being emptied?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 03-Jul-2006 14:44:01   

You should set each field's IsChanged property to true.

Since Unchanged fields won't get saved.