- Home
- General
- General Chat
WriteXML problem
Joined: 28-Nov-2005
Hi!
I'm using Target-per-entity hierarchy type. For example, the supertype is submission. Foundation has its supertype Registration. Registration has ist supertype Submission. Submission entity has Id property which is unique on persistency level. Submission(Id) -> Registration(SubmissionId) -> Foundation(SubmissonId)
I have problem with WriteXml method.
When i run this code:
FoundationEntity foundation = ... (fetched from database with subordinate objects)
string entityXML = string.Empty; foundation.WriteXml(XmlFormatAspect.Compact, out entityXML);
the exception is thrown with message: Item has already been added. Key in dictionary: "SubmissionId" Key being added: "SubmissionId" ...
The problem is because my FoundationEntity is inherited from Registration entity which is inherited from SubmissionEntity. SubmissionEntity has field id (primary key in database) and both RegistrationEntity and FoundationEntity has fields named SubmissionId.
here are some definitions of entities
public interface ISubmission : ISerializable public interface IRegistration : ISerializable, ISubmission public interface IFoundation : ISerializable, IRegistration
public class SubmissionEntity : EntityBase2, ISerializable, ISubmission public class RegistrationEntity : SubmissionEntity, ISerializable, IRegistration public class FoundationEntity : RegistrationEntity, ISerializable, IFoundation
How can I pass this problem?
Thanks in advance.
Joined: 28-Nov-2005
Otis wrote:
Do you use the latest runtime libraries? As this sounds like the bug which was fixed on 14-apr-2006 (see changelogs in the customer area)
Thank you for your reply. It works with latest runtime libraries but not as I expected. The XML I get is
<FoundationEntity Id="221507" SubmissionId="221507">
<Notes>
Spinnaker.Register.Repsis.Server.DataObjects.HelperClasses.EntityCollection
</Notes>
<Decree></Decree>
<Denials>
Spinnaker.Register.Repsis.Server.DataObjects.HelperClasses.EntityCollection
</Denials>
<Trustee></Trustee>
<ProcessingHistoryItems>
Spinnaker.Register.Repsis.Server.DataObjects.HelperClasses.EntityCollection
</ProcessingHistoryItems>
<Payments>
Spinnaker.Register.Repsis.Server.DataObjects.HelperClasses.EntityCollection
</Payments>
<Esubmission></Esubmission>
<IsNew>False</IsNew>
<TechnicalCorrections>
Spinnaker.Register.Repsis.Server.DataObjects.HelperClasses.EntityCollection
</TechnicalCorrections>
<Documents>
Spinnaker.Register.Repsis.Server.DataObjects.HelperClasses.EntityCollection
</Documents>
<Presenter>
[DomesticPersonEntity:LegalSubjectId=518496;RegistryCode=1510970732510;] [PersonEntity:LegalSubjectId=518496;FirstName=??????????;LastName=?????;IsRegistered=True;ExtraDataId=255387;] [LegalSubjectEntity:Id=518496;AddressId=1141528;ContactDataId=0;Note=;Text=;]
</Presenter>
<BusinessEntity>
[EnterpreneurEntity:LegalSubjectId=407899;DiscontinuanceType=Null;DiscontinuanceDate=1.1.0001 00:00:00;Title=ASD;TitleExtensionType=NoExtension;FounderName=asdf;BusinessActivityDescription=; IsPartnership=False;TitleTokenType=NoToken;CentralOfficeAdditionalData=;PreviousRegistrationMunicipalityId=0; StatusType=RegistrationProcess;]
</BusinessEntity>
</FoundationEntity>
I use modified templates from version "1.0.2005.1 Final"; released on "November 18th, 2005" with override ToString() method. I gets <Payments> Spinnaker.Register.Repsis.Server.DataObjects.HelperClasses.EntityCollection </Payments> but i expected to get <Payments> node that contains two <Payment> nodes with its specific attributes and nodes because WriteXML converts entity to XML, recursively.
What is the problem? Where am I wrong?
Thanks
Joined: 28-Nov-2005
Otis wrote:
Which ToString() method did you override? if you don't override it, is the XML then as expected?
I changed entityadapter.template. This code is added
/// <summary>
/// Displays some of object's attributes as string.
/// </summary>
/// <returns>
/// Concatenated object's attributes presented as 'AttributeName=Value;'
/// </returns>
public override string ToString()
{
StringBuilder text = new StringBuilder(60<[ If IsSubType ]> + 60<[ EndIf ]>);
text.Append("[<[CurrentEntityName]>Entity:");
<[Foreach EntityField CrLf]> text.Append("<[EntityFieldName]>=").Append(<[EntityFieldName]>.ToString()).Append(";");<[NextForeach]>
text.Append("]");
<[ If IsSubType ]>text.Append(base.ToString());<[ EndIf ]>
return text.ToString();
}
Again result is not as expected. Now xml is look like this
<FoundationEntity Id="221507" SubmissionId="221507">
<Notes>
Spinnaker.Register.Repsis.Server.DataObjects.HelperClasses.EntityCollection
</Notes>
<Decree></Decree>
<Denials>
Spinnaker.Register.Repsis.Server.DataObjects.HelperClasses.EntityCollection
</Denials>
<Trustee></Trustee>
<ProcessingHistoryItems>
Spinnaker.Register.Repsis.Server.DataObjects.HelperClasses.EntityCollection
</ProcessingHistoryItems>
<Payments>
Spinnaker.Register.Repsis.Server.DataObjects.HelperClasses.EntityCollection
</Payments>
<Esubmission></Esubmission>
<IsNew>False</IsNew>
<TechnicalCorrections>
Spinnaker.Register.Repsis.Server.DataObjects.HelperClasses.EntityCollection
</TechnicalCorrections>
<Documents>
Spinnaker.Register.Repsis.Server.DataObjects.HelperClasses.EntityCollection
</Documents>
<Presenter>
Spinnaker.Register.Repsis.Server.DataObjects.EntityClasses.DomesticPersonEntity
</Presenter>
<BusinessEntity>
Spinnaker.Register.Repsis.Server.DataObjects.EntityClasses.EnterpreneurEntity
</BusinessEntity>
</FoundationEntity>
If you look to previous message you will se that there is a diference between values in BusinessEntity and Presenter tags.
<!-- Old BusinessEntity -->
<BusinessEntity>
[EnterpreneurEntity:LegalSubjectId=407899;DiscontinuanceType=Null;DiscontinuanceDate=1.1.0001 00:00:00;Title=ASD;TitleExtensionType=NoExtension;FounderName=asdf;BusinessActivityDescription=; IsPartnership=False;TitleTokenType=NoToken;CentralOfficeAdditionalData=;PreviousRegistrationMunicipalityId=0; StatusType=RegistrationProcess;]
</BusinessEntity>
<!-- New BusinessEntity -->
<BusinessEntity>Spinnaker.Register.Repsis.Server.DataObjects.EntityClasses.EnterpreneurEntity</BusinessEntity>
<!-- Old Presenter -->
<Presenter>
[DomesticPersonEntity:LegalSubjectId=518496;RegistryCode=1510970732510;] [PersonEntity:LegalSubjectId=518496;FirstName=??????????;LastName=?????;IsRegistered=True;ExtraDataId=255387;] [LegalSubjectEntity:Id=518496;AddressId=1141528;ContactDataId=0;Note=;Text=;]
</Presenter>
<!-- New Presenter -->
<Presenter>
Spinnaker.Register.Repsis.Server.DataObjects.EntityClasses.DomesticPersonEntity
</Presenter>
My BusinessEntity is its specialisation EnterpreneurEntity and PresenterEntity is specialisation of DomesticPersonEntity which is specialisation of PersonEntity which is specialisation of LegalSubjectEntity.
So, without overrides of ToString methods on entity clases result is worst. I don't now if ToString method is the problem. I also expect to see, in both generated xml, for <Owner> (Owner is ApplicationUserEntity) some nodes and attributes for ApplicationUserEntity (Id, Name...), not only info Spinnaker.Register.Repsis.Server.DataObjects.EntityClasses.ApplicationUserEntity.
What to do?
I hope that you understand me. Sory for my bad English.
Thanks
Joined: 17-Aug-2003
I must say, I have no idea what the problem is or what you want to accomplish. .
You first ran into an issue, which was a bug, and when you used the fixed runtimes you got another problem but I have a hard time grasping what it is. You obviously get XML in a format you don't want / expect, is that correct? Am I also correct in that you want to add XML by overriding the ToString() method?
Joined: 28-Nov-2005
Dear Otis,
Thank you very much for all your previous time spent on my problem. Basically, what I am trying to achieve is the following:
- I need to delete the object with all its subordinate objects (the complete hierarchy). Please, take a note that I am aware that I need to delete one by one object, and that there are no shortcuts for doing that, except of the referential integrity mechanism implemented in a database (MS SQL)
2.Prior of doing that, I need to save the state of the object into xml file. In order to do that I have used WriteXML method but without success.
- I hope that it was clear enough from my previous notes, that object I intend to delete is inherited, as well as some of the objects which are subordinate to it, in its hierarchy. Thus, I would like to achieve the following:
<FoundationEntity Id="221507" SubmissionId="221507">
<Notes>
<Note Id=”11111”>
<Date>12/12/2005</Date>
<Description>Test1</Description>
</Note>
<Note Id=”22222”>
<Date>11/11/2005</Date>
<Description>Test2</Description>
</Note>
</Notes>
...
< EnterpreneurEntity Id=”407899” LegalSubjectId=”407899”>
<DiscontinuanceType>1</DiscontinuanceType>
<DiscontinuanceDate>1.1.0001 00:00:00</DiscontinuanceDate>
<Title>My title</Title>
...
</ EnterpreneurEntity >
</FoundationEntity>
But I keep getting the following result:
<FoundationEntity Id="221507" SubmissionId="221507">
<Notes>
Spinnaker.Register.Repsis.Server.DataObjects.HelperClasses.EntityCollection
</Notes>
...
<BusinessEntity>
Spinnaker.Register.Repsis.Server.DataObjects.EntityClasses.EnterpreneurEntity
</BusinessEntity>
</FoundationEntity>
where, please keep in mind, EnterpreneurEntity inherits BusinessEntity class.
- Please confirm that OnDelete event raised on DataAccessAdapter is the he best possible place where I can implement this kind of functionality
Thank you again for your attention and kind help.
Joined: 21-Aug-2005
I'm not aware of the origin of the problem, but I'll do some guessing, trying to help.
I use modified templates from version "1.0.2005.1 Final"; released on "November 18th, 2005" with override ToString() method.
If you don't use this modified template, and use the templates that was shipped with the latest version of the LLBLGen Pro without modifying them, would this make any difference?
What if you use modify the latest templates? would this make any different?
Would you please explain why do you override the ToString()?