The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

ES collection from LINQ to XML

Last post 06-30-2008, 3:55 AM by kimobcn. 3 replies.
Sort Posts: Previous Next
  •  06-26-2008, 9:35 AM 10011

    ES collection from LINQ to XML

    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

     

    Filed under:
  •  06-26-2008, 9:53 AM 10012 in reply to 10011

    Re: ES collection from LINQ to XML

    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
  •  06-27-2008, 10:09 AM 10031 in reply to 10012

    Re: ES collection from LINQ to XML

    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.....

     

  •  06-30-2008, 3:55 AM 10064 in reply to 10031

    Re: ES collection from LINQ to XML

    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

     

View as RSS news feed in XML