Exemple #1
0
        /// <summary>
        /// Fill the shadow properties during update considering the tracker
        /// </summary>
        private void UpdateShadowProperties(T entity)
        {
            DbContext.WriteDebug("Update Shadow Properties");
            var entry         = DbContext.Entry(entity);
            var propertyNames = entry.Metadata
                                .GetProperties()
                                .Select(p => p.Name);
            var props = propertyNames.Select(p => entry.Property(p))
                        .Where(e => e.IsModified);
            var entityType = typeof(T);

            foreach (var prop in props)
            {
                if (prop.Metadata
                    .IsShadowProperty())
                {
                    continue;
                }
                var searchInfo = EntityTypeBuilderExtensions.GetShadowField(entityType, prop);
                var value      = prop.CurrentValue;

                if (searchInfo != null && value != null)
                {
                    DbContext.Entry(entity)
                    .Property(searchInfo.ColumnName)
                    .CurrentValue =
                        value.ToString()
                        .ToSearchable(searchInfo.SearchableType);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Fill the shadow properties during insert
        /// </summary>
        private void InsertShadowProperties(T entity)
        {
            DbContext.WriteDebug("Insert Shadow Properties");
            var props = entity.GetType()
                        .GetProperties();
            var entityType = typeof(T);

            foreach (var prop in props)
            {
                var searchInfo = EntityTypeBuilderExtensions.GetShadowField(entityType, prop);
                var value      = prop.GetValue(entity);

                if (searchInfo != null && value != null)
                {
                    DbContext.WriteDebug($"Shadow Properties [{searchInfo.ColumnName}] = {value}");
                    DbContext.Entry(entity)
                    .Property(searchInfo.ColumnName)
                    .CurrentValue =
                        value.ToString()
                        .ToSearchable(searchInfo.SearchableType);
                }
            }
        }