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
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
I could elaborate a little.
Fragment of the XML:
<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()
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.....
I think I solved the problem myself. Instead of Addnew I set the FK value and called AttachEntity.
For Each Item As Funcionario In ident Item.TramitesId = 1 tramite.FuncionarioCollectionByTramitesId.AttachEntity(Item) Next tramite.Save()
Thanks for your support