Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

EntityTools

Daniel Svensson edited this page Apr 17, 2019 · 1 revision

Description

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.

Documentation

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

Examples

Entity cloning

{code:c#} Person newPerson = newPerson(); newPerson.ApplyState(Nothing, existingPerson.ExtractState(ExtractType.ModifiedState); newPerson.PersonId = Guid.NewGuid(); context.Persons.Add(newPerson); {code:c#}

Partial Save (i.e. save only a single change instead of the whole DomainContext)

{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

Export EntityList and save to Isolated Storage

{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#}

Import information from Isolated Storage into EntityList

{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.