THESE FORUMS ARE NOW FROZEN
Please choose "Forums" from the Main menu of www.entityspaces.net to get to our new forums.

ES collection from LINQ to XML

rated by 0 users
This post has 3 Replies | 1 Follower

Top 500 Contributor
Posts 3
kimobcn Posted: 06-26-2008 9:35 AM

Hi,

 I need to read, parse and write (insert) to a database information contained in XML messages coming from our customers. Is there a way to target an ES collection as the results of a LINQ to XML query?

The basic idea is:

Read XML

Execute a LINQ to XML putting the result in an ES Collection

Insert the collection to the Database 

Thanks,

 

Jaume

 

Top 10 Contributor
Posts 3,881

I will do an experiment tonight and get back to you, we currently support only LINQ to SQL but my guess is this will plug in nicely, we could include it in a maintenance release if so.

EntitySpaces | Twitter | BLOG | Please honor our Software License

Top 500 Contributor
Posts 3

I could elaborate a little.

Fragment of the XML:

Code:
					<Identificacion>
						<Tipo_Personalidad>1</Tipo_Personalidad>
						<Nombre>NOMBRE FUNCIONARIO</Nombre>
						<Apellidos>APELLIDOS FUNCIONARIO</Apellidos>
						<Identificador_Administrativo>
							<Tipo>3</Tipo>
							<Numero_Documento>99999999L</Numero_Documento>
						</Identificador_Administrativo>
					</Identificacion>
And my code
Code:
        Dim tramite As New Tramites
        tramite.LoadByPrimaryKey(1)
        Dim adminXML As XDocument = XDocument.Load("C:\test\propiedad.xml")

     
        Dim ident = From id In adminXML...<Identificacion> _
                   Select New Funcionario With {.Nombre = id...<Nombre>.Value, _
                    .Apellidos = id...<Apellidos>.Value, _
                    .Nif = id...<Numero_Documento>.Value}


        For Each Item As Funcionario In ident
            Dim funcion As Funcionario = tramite.FuncionarioCollectionByTramitesId.AddNew
            'This works, but it's not very elegant
            funcion.Apellidos = Item.Apellidos
            funcion.Nif = Item.Nif
            funcion.Nombre = Item.Nombre
            '...
            'and so on... More than 100 fields in real life
            

            'This (what I want) does not work
            funcion = Item
            'The ES object 'funcion' is filled with the values from
            ' 'Item' but only writes NULLs to the database.

        Next
        tramite.Save()

 

If I print the contents of the 'funcion' instance, the object is filled with the correct data in both cases, but if I use "funcion=item" the save just inserts the ID, FK ID and nulls.

I am lost.....

 

Top 500 Contributor
Posts 3

I think I solved the problem myself. Instead of Addnew I set the FK value and called AttachEntity.

Code:
        For Each Item As Funcionario In ident
            Item.TramitesId = 1
            tramite.FuncionarioCollectionByTramitesId.AttachEntity(Item)
        Next
        tramite.Save()

 

Thanks for your support

 

Page 1 of 1 (4 items) | RSS
Copyright © 2005 - 2009, EntitySpaces, LLC