Hello,
I tried to copy an entity object using the binaryformatter, however before saving I need to change the primary key to another value. This attempt produces an error.
Here is my code:
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
//Copy Quiz
BusinessObjects.QuizModule fromquiz = new BusinessObjects.QuizModule();
fromquiz.LoadByPrimaryKey(int.Parse(fromNodeID));
bf.Serialize(ms, fromquiz);
ms.Position = 0;
BusinessObjects.QuizModule toquiz = new BusinessObjects.QuizModule();
toquiz = (BusinessObjects.QuizModule)bf.Deserialize(ms);
ms.Close();
toquiz.NodeID = int.Parse(toNodeID); //Change PK id to new one
toquiz.Save(); //Error on saving
Error and stack trace:
Incorrect syntax near the keyword 'WHERE'.
at EntitySpaces.Core.esEntity.SaveToProvider(esSqlAccessType sqlAccessType)
at EntitySpaces.Core.esEntity.Save(esSqlAccessType sqlAccessType)
at EntitySpaces.Core.esEntity.Save()
at PPCS.modules.QuizModule.CopyModuleContent(String fromNodeID, String toNodeID) in C:\Documents and Settings\pixel\My Documents\Visual Studio 2005\Projects\PPCS\modules\QuizModule.ascx.cs:line 66
I tried to figure out another way to copy an entity by iterating through columns, but the es.Meta.Columns is read only???
So, I can't do this: toquiz.es.Meta.Columns[ i ] = fromquiz.es.Meta.Columns[ i ];
Please, help. Thanks!