WriteXML , please

Posts   
 
    
gj1118
User
Posts: 30
Joined: 21-Jul-2010
# Posted on: 21-Jul-2010 15:54:59   

Hi

I am using LLBLGEN 2.6 Final, June26th, 2008

I have to generate an XML string from data which is to be retireved from 3 different tables here is the table structure

Table A has a one to many relation with Table B Table B has a many to one relation with Table C

My main problem is that the xml that is being generated as only values from table A and not from the rest of the two tables.

Any help , would be appreciated

Thanks and Regards

G

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Jul-2010 16:36:18   

Please post a code snippet of what you have been trying.

btw, you are using a very old version of the runtime library, please upgrade to the latest build of v.2.6

gj1118
User
Posts: 30
Joined: 21-Jul-2010
# Posted on: 21-Jul-2010 16:44:35   

Thanks for responding..


            PredicateExpression Filter = new PredicateExpression();
            Filter.Add(ContactFields.ContactLastName == lastName);

            RelationCollection Relations = new RelationCollection();
            Relations.Add(ContactEntity.Relations.DataEntityUsingContactId);
            

            return GetContacts(Filter, null, Relations);


I am gettting the collection from the code above and generating xml out of that collection using the code below


                string xml;
                Contacts.WriteXml(XmlFormatAspect.Compact | XmlFormatAspect.DatesInXmlDataType | XmlFormatAspect.MLTextInCDataBlocks,out xml);

                TextBoxXML.Text += xml;

and this is the xml I am getting


<Entity ContactId="2">
  <EntityCollectionReference PropertyName="Data">
    <Data>
      <Entities />
      <AllowNew>true</AllowNew>
      <AllowRemove>true</AllowRemove>
      <AllowEdit>true</AllowEdit>
    </Data>
  </EntityCollectionReference>
  <AlwaysFetchData>false</AlwaysFetchData>
  <AlreadyFetchedData>false</AlreadyFetchedData>
  <EntityCollectionReference PropertyName="CustomFieldCollectionViaData">

    <CustomFieldCollectionViaData>
      <Entities />
      <AllowNew>true</AllowNew>
      <AllowRemove>true</AllowRemove>
      <AllowEdit>true</AllowEdit>
    </CustomFieldCollectionViaData>
  </EntityCollectionReference>
  <AlwaysFetchCustomFieldCollectionViaData>
  false</AlwaysFetchCustomFieldCollectionViaData>
  <AlreadyFetchedCustomFieldCollectionViaData>
  false</AlreadyFetchedCustomFieldCollectionViaData>
  <EntityReference PropertyName="Client" />
  <AlwaysFetchClient>false</AlwaysFetchClient>
  <AlreadyFetchedClient>false</AlreadyFetchedClient>
  <ClientReturnsNewIfNotFound>true</ClientReturnsNewIfNotFound>
  <IsNew>false</IsNew>
  <ObjectID>77986a15-d797-4a54-817c-3060872c90d9</ObjectID>
  <Fields>
    <ContactId>
      <CurrentValue>2</CurrentValue>
      <DbValue>2</DbValue>
      <IsChanged>False</IsChanged>
      <IsNull>False</IsNull>
    </ContactId>
    <ContactFirstName>
      <CurrentValue>Devin</CurrentValue>
      <DbValue>Devin</DbValue>
      <IsChanged>False</IsChanged>
      <IsNull>False</IsNull>
    </ContactFirstName>
    <ContactLastName>
      <CurrentValue>Gauthier</CurrentValue>
      <DbValue>Gauthier</DbValue>
      <IsChanged>False</IsChanged>
      <IsNull>False</IsNull>
    </ContactLastName>
    <ClientId>
      <CurrentValue>2</CurrentValue>
      <DbValue>2</DbValue>
      <IsChanged>False</IsChanged>
      <IsNull>False</IsNull>
    </ClientId>
  </Fields>
  <IsDirty>False</IsDirty>
  <EntityState>Fetched</EntityState>
  <SavedFieldSets />
</Entity>


Contact has a one to many relation with Table Data Data has a many to one relation with CustomField

The logic is as follows

A contact can have multiple custom fields. these custom fields are stored in the table CustomField. The data for these customFields is being stored in the table data

thanks once again!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Jul-2010 16:55:35   

Your code only fetches Contacts, and the relation added to Data is not used nor needed.

gj1118
User
Posts: 30
Joined: 21-Jul-2010
# Posted on: 21-Jul-2010 17:07:15   

so, could you please let me know, how to get all the data from all the three tables, for a contact's last name [contact's last name is a column in the table Contact]

Thanks for your help ...

arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 21-Jul-2010 20:57:23   

Look at using prefetch paths to retrieve the associated entities.

gj1118
User
Posts: 30
Joined: 21-Jul-2010
# Posted on: 21-Jul-2010 21:16:47   

I am sorry, I have nver worked, with prefetch paths before.. could you please pass me an example or point to it ..

Thanks for your time and patience

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Jul-2010 07:36:29   
David Elizondo | LLBLGen Support Team
gj1118
User
Posts: 30
Joined: 21-Jul-2010
# Posted on: 22-Jul-2010 19:33:21   

Hi,thanks for all the replies .. your help was appreciated.

With the help of the documentation link that was provided, [thanks @daelmo simple_smile ] i got this




            ContactCollection Contacts = new ContactCollection();

            IPrefetchPath prefetchPath = new PrefetchPath((int)EntityType.ContactEntity);

            IPrefetchPathElement DataElement = prefetchPath.Add(ContactEntity.PrefetchPathData);
            DataElement.SubPath.Add(DataEntity.PrefetchPathCustomField);

            PredicateExpression Filter = new PredicateExpression();
            Filter.Add(ContactFields.ContactLastName == lastName);

            Contacts.GetMulti(Filter, prefetchPath);

            return Contacts;


but this code here is generating me a lot of xml.. not something like the Serialization library of .Net

I used this approach to generate the xml


   string xml;
                Contacts.WriteXml(XmlFormatAspect.Compact | XmlFormatAspect.DatesInXmlDataType | XmlFormatAspect.MLTextInCDataBlocks,out xml);

                TextBoxXML.Text += xml;

With respect to this, I read some articles, about LLBLGen, and i came accross someone who said that all the extra information needs to be there, otherwise llblgen will not be able to deserialize the object back ..

I just would like to ask this , "Is this true?"

thanks once again!

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 22-Jul-2010 21:27:03   

http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/gencode_xmlsupport.htm#readingwriting

You can specify different formats for the XML. It depends on what you are going to do with it at the other end as to which format you choose.

Matt

gj1118
User
Posts: 30
Joined: 21-Jul-2010
# Posted on: 22-Jul-2010 21:49:33   

Thanks Matt for your time and patience

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 22-Jul-2010 21:54:08   

No problem, that's what we're here for simple_smile

Matt