public static void LoadFacetValues <TEntity>(this TEntity entity, EntityDbContext entityDbContext)
            where TEntity : IEntity, IExtensible
        {
            var FacetData = entity.FindExtension <EntityFacetData>();

            if (FacetData != null)
            {
                return;
            }

            var cachedEntityTypeSet = entityDbContext.GetCachedDataSet <CachedEntityType>();
            var cachedFacetset      = entityDbContext.GetCachedDataSet <CachedFacet>();
            var FacetValueSet       = entityDbContext.GetDataSet <FacetValue>();

            CachedEntityType entityType = cachedEntityTypeSet.GetByType <TEntity>();

            var Facets = cachedFacetset.GetAll()
                         .Where(a => a.EntityTypeId == entityType.Id)
                         .Where(a => a.DoQualifiersMatchForEntity(entity))
                         .ToList();

            var FacetIds = Facets.Select(a => a.Id)
                           .ToList();
            var FacetValues = FacetValueSet.Where(a => FacetIds.Contains(a.FacetId))
                              .ToList();

            var values = Facets.ToDictionary(
                a => a,
                a => FacetValues.FirstOrDefault(b => b.FacetId == a.Id) ?? FacetValueSet.Create());

            FacetData = new EntityFacetData(values);

            entity.AddOrReplaceExtension(FacetData);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called just after changes are saved to the database.
        /// </summary>
        /// <param name="entityDbContext">The database context.</param>
        /// <param name="success"><c>true</c> if the save operation succeeded.</param>
        public void PostSaveChanges(EntityDbContext entityDbContext, bool success)
        {
            if (success)
            {
                foreach (var entry in _modifiedEntities)
                {
                    var cachedType = _options.CachedTypesByEntity[entry.Key.GetType()].CachedType;
                    var set        = entityDbContext.GetCachedDataSet(cachedType);

                    set.EntityChanged(entry.Key, entry.Value);
                }
            }
        }