반사 필터 식 트리로 구성 EF 글로벌 필터와

1. 소프트 삭제 인터페이스

(1 개)  공공  인터페이스 ISoftDelete은
 2      {
 3          부울이 isDeleted를 { GET ; 설정 ; }
 4      }

2. 엔티티 클래스 구현

(1 개)  공공  클래스 TestDeleted : ISoftDelete
 2      {
 3          공공  INT 아이디 { GET ; 설정 ; }
 4  
5          공공  문자열 이름 { 얻을 ; 설정 ; }
 6          공공  부울은 isDeleted를 { GET ; 설정 ; }
 7  
8  
9      }

3.modelBuilder 확장 클래스

1  공용  정적  클래스 CustomModelBuilderExtensions
 2-      {
 3          공공  정적  무효 AddSoftDeleted ( 모델 빌더 빌더)
 -4-          {
 5              VAR entityTypes builder.Model.GetEntityTypes = () 여기서 (E =>. 대해서 typeof (ISoftDelete) .IsAssignableFrom (e.ClrType));
6              의 foreach ( VAR의 entityType entityTypes)
 7              {
 8                  VAR 파라미터 = Expression.Parameter (entityType.ClrType);
9  
10                  VARpropertyMethodInfo = 대해서 typeof (EF) .GetMethod ( " 속성 " ) .MakeGenericMethod ( 대해서 typeof ( 부울을 ));
11  
12                  VAR isDeletedProperty = Expression.Call (propertyMethodInfo, 파라미터 Expression.Constant ( " isDeleted를 " ));
13  
14                  BinaryExpression을 compareExpression = Expression.MakeBinary (ExpressionType.Equal, isDeletedProperty, Expression.Constant ( 거짓 ));
15  
16                  VAR의 lambdaExpression = Expression.Lambda (compareExpression 파라미터);
17  
18                 builder.Entity (entityType.ClrType) .HasQueryFilter (lambdaExpression);
19              }
 20          }
 21      }

4. 데이터베이스 마이그레이션

글로벌 절차를 이용하여 스크리닝 방법 5. OnModelCreating

1 builder.AddSoftDeleted ();

 

 

 

 

 

 

 

 

추천

출처www.cnblogs.com/Spinoza/p/11831205.html