Esempio n. 1
0
        async Task DoDelete(Entity entity, DeleteBehaviour behaviour)
        {
            // Raise deleting event
            if (!IsSet(behaviour, DeleteBehaviour.BypassDeleting))
            {
                var deletingArgs = new System.ComponentModel.CancelEventArgs();
                await Entity.Services.RaiseOnDeleting(entity, deletingArgs);

                if (deletingArgs.Cancel)
                {
                    Cache.Remove(entity);
                    return;
                }
            }

            if (SoftDeleteAttribute.IsEnabled(entity.GetType()) && !SoftDeleteAttribute.Context.ShouldByPassSoftDelete())
            {
                SoftDeleteAttribute.MarkDeleted(entity);
                await GetProvider(entity).Save(entity);
            }
            else
            {
                await GetProvider(entity).Delete(entity);
            }
        }
        internal static DataProviderMetaData Generate(Type type)
        {
            var tableName = TableNameAttribute.GetTableName(type);

            return(new DataProviderMetaData(type)
            {
                BaseClassTypesInOrder = GetParents(type),
                DrivedClassTypes = GetDrivedClasses(type),
                Properties = GetProperties(type).ToArray(),
                Schema = SchemaAttribute.GetSchema(type),
                TableName = tableName,
                TableAlias = tableName,
                IsSoftDeleteEnabled = SoftDeleteAttribute.IsEnabled(type, inherit: false)
            });
        }
        static IEnumerable <PropertyData> GetProperties(Type type)
        {
            var infos = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            foreach (var(info, dbProp) in FilterProperties(infos))
            {
                yield return(GetUserDefinedPropertyData(info, dbProp));
            }

            if (infos.None(t => PrimaryKeyAttribute.IsPrimaryKey(t)))
            {
                yield return(GetDefaultIdPropertyData(type));
            }

            if (SoftDeleteAttribute.IsEnabled(type, inherit: false))
            {
                yield return(GetDeletedPropertyData(type));
            }

            yield return(GetOriginalIdPropertyData(type));
        }