public static void SetCascadeQueryFilter(this IMutableEntityType entityData,
                                                 CascadeQueryFilterTypes queryFilterType, IUserId userIdProvider)
        {
            var methodName   = $"Get{queryFilterType}Filter";
            var methodToCall = typeof(CascadeQueryFilterExtensions)
                               .GetMethod(methodName,
                                          BindingFlags.NonPublic | BindingFlags.Static)
                               .MakeGenericMethod(entityData.ClrType);
            var filter = methodToCall
                         .Invoke(null, new object[] { userIdProvider });

            entityData.SetQueryFilter((LambdaExpression)filter);

            if (queryFilterType == CascadeQueryFilterTypes.CascadeSoftDelete)
            {
                entityData.AddIndex(entityData.FindProperty(nameof(ICascadeSoftDelete.SoftDeleteLevel)));
            }
            if (queryFilterType == CascadeQueryFilterTypes.CascadeSoftDeleteAndUserId ||
                queryFilterType == CascadeQueryFilterTypes.CascadeAndSingleAndUserId)
            {
                entityData.AddIndex(entityData.FindProperty(nameof(IUserId.UserId)));
            }
            if (queryFilterType == CascadeQueryFilterTypes.CascadeAndSingleAndUserId)
            {
                entityData.AddIndex(entityData.FindProperty(nameof(ISingleSoftDelete.SoftDeleted)));
            }
        }
예제 #2
0
        /// <summary>
        ///     Gets the index defined on the given property or creates a new one if one is not already defined.
        /// </summary>
        /// <param name="entityType"> The entity type to get or add the index to. </param>
        /// <param name="properties"> The properties to be indexed. </param>
        /// <returns> The existing or newly created index. </returns>
        public static IMutableIndex GetOrAddIndex(
            [NotNull] this IMutableEntityType entityType, [NotNull] IReadOnlyList <IMutableProperty> properties)
        {
            Check.NotNull(entityType, nameof(entityType));

            return(entityType.FindIndex(properties) ?? entityType.AddIndex(properties));
        }
예제 #3
0
        /// <summary>
        ///     Adds an index to this entity.
        /// </summary>
        /// <param name="entityType"> The entity type to add the index to. </param>
        /// <param name="property"> The property to be indexed. </param>
        /// <returns> The newly created index. </returns>
        public static IMutableIndex AddIndex(
            [NotNull] this IMutableEntityType entityType, [NotNull] IMutableProperty property)
        {
            Check.NotNull(entityType, nameof(entityType));

            return(entityType.AddIndex(new[] { property }));
        }
예제 #4
0
 private static void CloneIndexes(IReadOnlyEntityType sourceEntityType, IMutableEntityType targetEntityType)
 {
     foreach (var index in sourceEntityType.GetDeclaredIndexes())
     {
         var clonedIndex = targetEntityType.AddIndex(
             index.Properties.Select(p => targetEntityType.FindProperty(p.Name)).ToList());
         clonedIndex.IsUnique = index.IsUnique;
         index.GetAnnotations().ForEach(annotation => clonedIndex[annotation.Name] = annotation.Value);
     }
 }
        public static void AddSoftDeleteQueryFilter(this IMutableEntityType entityData)
        {
            var methodToCall = typeof(SoftDeleteQueryExtension).GetMethod(nameof(GetSoftDeleteFilter),
                                                                          BindingFlags.NonPublic | BindingFlags.Static)
                               .MakeGenericMethod(entityData.ClrType);
            var filter = methodToCall.Invoke(null, new object[] { });

            entityData.SetQueryFilter((LambdaExpression)filter);
            entityData.AddIndex(entityData.FindProperty(nameof(ISoftDelete.SoftDeleted)));
        }
            private void AddSoftDeleteQueryFilter(IMutableEntityType entityData)
            {
                var methodToCall = GetType()
                                   .GetMethod(nameof(GetSoftDeleteFilter),
                                              BindingFlags.NonPublic | BindingFlags.Instance)
                                   .MakeGenericMethod(entityData.ClrType);
                var filter = methodToCall.Invoke(this, new object[] { });

                entityData.SetQueryFilter((LambdaExpression)filter);
                entityData.AddIndex(entityData.FindProperty(nameof(ISingleSoftDelete.SoftDeleted)));
            }
예제 #7
0
        public static void AddSoftDeleteQueryFilter(                                    //#C
            this IMutableEntityType entityData,                                         //#D
            MyQueryFilterTypes queryFilterType,                                         //#E
            IUserId userIdProvider = null)                                              //#F
        {
            var methodName   = $"Get{queryFilterType}Filter";                           //#G
            var methodToCall = typeof(SoftDeleteQueryExtensions)                        //#G
                               .GetMethod(methodName,                                   //#G
                                          BindingFlags.NonPublic | BindingFlags.Static) //#G
                               .MakeGenericMethod(entityData.ClrType);                  //#G
            var filter = methodToCall                                                   //#G
                         .Invoke(null, new object[] { userIdProvider });                //#G

            entityData.SetQueryFilter((LambdaExpression)filter);                        //#H
            if (queryFilterType == MyQueryFilterTypes.SoftDelete)
            {
                entityData.AddIndex(entityData.FindProperty(nameof(ISoftDelete.SoftDeleted)));
            }
            if (queryFilterType == MyQueryFilterTypes.UserId)
            {
                entityData.AddIndex(entityData.FindProperty(nameof(IUserId.UserId)));
            }
        }