In this situation I am trying to perform a data import from an XML file to a database using LINQ to XML and LINQ to SQL.
Here\'s my LINQ data model:
you can construct your entity set from a IEnumerable using a helper class, something like:
public static class EntityCollectionHelper
{
public static EntitySet<T> ToEntitySet<T>(this IEnumerable<T> source) where T:class
{
EntitySet<T> set = new EntitySet<T>();
set.AddRange(source);
return set;
}
}
and use it like so :
PageContents = (from pc in el.Elements()
where pc.Name.LocalName == "revision"
select new PageContent()
{
Content = pc.Elements().Where(e => e.Name.LocalName=="text").First().Value,
Username = pc.Elements().Where(e => e.Name.LocalName == "contributor").First().Elements().Where(e => e.Name.LocalName == "username").First().Value,
DateTime = DateTime.Parse(pc.Elements().Where(e => e.Name.LocalName == "timestamp").First().Value)
}).ToEntitySet()