-
Notifications
You must be signed in to change notification settings - Fork 1
EntityTools
EntityTools is modeled after Silverlight Contrib/Silverlight Extensions. It currently has a library of extentions for the Entity and EntitySet which provide data import and export abilities.
Online documentation can be found at http://www.riaservicesblog.net/RiaServicesContrib.EntityTools Offline documentation is available at http://www.riaservicesblog.net/RiaServicesContrib.EntityTools/Entity%20Tools.chm
{code:c#} Person newPerson = newPerson(); newPerson.ApplyState(Nothing, existingPerson.ExtractState(ExtractType.ModifiedState); newPerson.PersonId = Guid.NewGuid(); context.Persons.Add(newPerson); {code:c#}
{code:c#} PersonDomainContext tempContext = new PersonDomainContext(); Person savePerson = newPerson(); tempContext.Persons.Add(savePerson); savePerson.ApplyState(originalPerson.ExtractState(ExtractType.OriginalState, ExtractType.ModifiedState); tempContext.SubmitChanges(); {code:c#}
A more powerful example of performing a partial save can be found at http://riaservicescontrib.codeplex.com/wikipage?title=PartialSaveWithEntityGraph&referringTitle=EntityGraphs%20
{code:c#} using IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication() { using IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(fileName, FileMode.OpenOrCreate, isf) { DataContractSerializer serializer = new DataContractSerializer(typeof(List)); serializer.WriteObject(isfs, context.Persons.Export()); isfs.Close(); } } {code:c#}
{code:C#} using IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication() { using IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(fileName, FileMode.Open, isf) { DataContractSerializer serializer = new DataContractSerializer(typeof(List)); context.Persons.Import(serializer.ReadObject(isfs)); isfs.Close(); } } {code:c#}
Some things which might not be obvious is that the Export functionality can also be done against a LINQ query, allowing partial exports of entities.