Hi there,
I attempted to replicate the example code in the documentation topic "Generated code - Excluding / Including fields for fetches, Adapter".
My code is:
public EntityCollection<IllustrationEntity> GetIllustrationsExcludingDiagram(out IllustrationEntity refilledEntity)
{
ExcludeIncludeFieldsList excludedFields = new ExcludeIncludeFieldsList();
excludedFields.Add(IllustrationFields.Diagram);
EntityCollection<IllustrationEntity> illlustrations = new EntityCollection<IllustrationEntity>();
SortExpression sorter = new SortExpression(IllustrationFields.IllustrationId | SortOperator.Descending);
using (DataAccessAdapter productsAdapter = DataAccess.AdaptorFactory.GetNewAdaptor(true))
{
productsAdapter.FetchEntityCollection(illlustrations, null, 0, sorter, null, excludedFields);
}
// Now, re-hydrate one of the entities.
refilledEntity = new IllustrationEntity(1);
using (DataAccessAdapter productsAdapter = DataAccess.AdaptorFactory.GetNewAdaptor(true))
{
productsAdapter.FetchEntity(refilledEntity, null, null, excludedFields);
}
using (DataAccessAdapter productsAdapter = DataAccess.AdaptorFactory.GetNewAdaptor(true))
{
productsAdapter.FetchExcludedFields(illlustrations, excludedFields);
productsAdapter.FetchExcludedFields(refilledEntity, excludedFields);
}
return illlustrations;
}
An exception is thrown:
ORMEntityOutOfSyncException
The entity is out of sync with its data in the database. Refetch this entity before using this in-memory instance.
Can anyone please explain where I have gone wrong.
Using the AdventureWorks database.
Thanks