views:

41

answers:

0

I have a program that uses a lot of xml serialization for storage purposes, because at this point in time a database is inaccessible for the specific project.

Is there any inherit way to lace 'Ids' in foreign collections similar to how they would work as foreign keys in a database? For example...

<Client>
 <Name>Client A</Name>
 <Addresses>
   <Address>01</Address>
   <Address>02</Address>
 </Addresses>
</Client>

<Addresses>
 <Address>
  <Id>01</Id>
  <Details> ... </Details>
  <ZipCode>00000</ZipCode>
 </Address>
</Addresses>

--------------------
[XmlSerialized]
public class Client
{
 List<int> Addresses { get; set; }
}

public class ClientViewModel
{
 List<Address> Addresses { get; set; }
}

public void LaceAddresses( Client c, List<Address> addresses )
{
 List<Address> clientAddresses = new List<Address>();
 foreach( Address a in c.Addresses )
   clientAddresses.Add( addresses.Single( address => address.Id == a.Id ) );

 ClientViewModel cvm = 
 {
   Addresses = clientAddresses
 }
}

I know this isn't a good example, and the best choice is to simply use a database. But right now that isn't an option.

Each of the lists is stored in a separate .xml file for organizational concerns. I have code that just iterates and laces up based on id, but I know XML is pretty robust and I was thinking that this can't be too atypical. Any thoughts?

This is coded in C# 3.5.