title: Is it possible to have fall-back for empty values in a LINQ query considering locale?
body: <p>I'm creating a C# .NET 3.5 website. In this website some content is read from an XML file. This XML file is saved from an Excel file, so basically the Excel is a kind of content management system (I cannot use a database in this situation). I am using LINQ to XML to get collections of the content objects so I can work with them on the webforms. I am a just starting with LINQ, but I know the basics like grouping and ordering.</p>
  
  <p>I am using the following code to read the content into a collection (in this case a list of video's):</p>
  
  <pre><code>string path = String.Format(server.MapPath("~/App_Data/Content.{0}.xml"), culture);
  XDocument source = cache.Get(path);
  
  bool boolValue = false;
  
  var query =
      from video in source.Descendants("Video")
      where video.Attribute("Id").Value != null
  
      /* Temporary values */
      let featured = video.Attribute("IsFeatured").Value
  
      select new Video
      {
          Culture = culture, 
          Id = video.Attribute("Id").Value, 
          Name = video.Element("Name").Value,
          Description = video.Element("Description").Value,
          Category = video.Element("Category").Value,
          Url = video.Element("Url").Value,
          IsFeatured = Boolean.TryParse(featured, out boolValue) ? boolValue : false, 
          Tags = video.Element("Tags").Value.Split(',').Select(t =&gt; t.Trim()).ToArray()
      };
  
  return query.ToList();
  </code></pre>
  
  <p>In the current situation there is one xml file per culture. A mayor drawback is that it will result in a lot of redundant values. To make it more manageable, i will have just one xml file.</p>
  
  <p>I would like to create a situation where rows with the same id share content so I don't have to add redundant values. Is it possible to have a "fall-back" for the empty values?</p>
  
  <p><strong>Example: creating the xml(excel) file</strong></p>
  
  <p>If I want to read Swiss German content the query will look for values where the locale is 'de-ch'. If there are still empty values the query will look for a 'higher' locale, in this case 'de', and last if there are still empty values it will take them from the default locale, which is 'en'.</p>
  
  <p>Let's say I have a Product object.
  It has a name, a description and a price. </p>
  
  <p><strong>Start with English (en)</strong></p>
  
  <p>I will start with the culture 'en', because this is my standard culture.
  In the excel I would create a row:</p>
  
  <ul>
  <li>Locale = en</li>
  <li>Name = Product 1</li>
  <li>Description= English description</li>
  <li>Price = 100</li>
  </ul>
  
  <p><strong>Then German (de)</strong>
  Then i want a translation in German, so I add another row, but I leave the Name and price empty, because there are the same.</p>
  
  <ul>
  <li>Locale = de</li>
  <li>Name = </li>
  <li>Description= German description</li>
  <li>Price = </li>
  </ul>
  
  <p><strong>Then Swiss German (de-ch)</strong>
  Here i only want to add the price, because it has a different currency.</p>
  
  <ul>
  <li>Locale = de-ch</li>
  <li>Name = </li>
  <li>Description =</li>
  <li>Price = 222</li>
  </ul>
  
  <p><strong>The result I am aiming for in LINQ</strong></p>
  
  <p>When the culture would be de-ch, the returning object in LINQ will have the following values:</p>
  
  <ul>
  <li>Locale = de-ch</li>
  <li>Name = Product 1 (from en)</li>
  <li>Description = German description (from de)</li>
  <li>Price = 222 (from de-ch)</li>
  </ul>
  
  <p>I think I will be able to do it in normal C# with some loops, but how would you do this in Linq? Maybe someone can give some direction how I can achieve this in LINQ.</p>