Пример #1
0
 /// <inheritdoc />
 public override void ProcessModelFinalizing(
     IConventionModelBuilder modelBuilder,
     IConventionContext <IConventionModelBuilder> context)
 {
     foreach (var entityType in modelBuilder.Metadata.GetEntityTypes())
     {
         var definingQuery = InMemoryEntityTypeExtensions.GetDefiningQuery(entityType);
         if (definingQuery != null)
         {
             InMemoryEntityTypeExtensions.SetDefiningQuery(
                 entityType, (LambdaExpression)DbSetAccessRewriter.Rewrite(modelBuilder.Metadata, definingQuery));
         }
     }
 }
        /// <summary>
        ///     Validates the configuration of defining queries in the model.
        /// </summary>
        /// <param name="model"> The model to validate. </param>
        /// <param name="logger"> The logger to use. </param>
        protected virtual void ValidateDefiningQuery(
            [NotNull] IModel model, [NotNull] IDiagnosticsLogger <DbLoggerCategory.Model.Validation> logger)
        {
            Check.NotNull(model, nameof(model));

            foreach (var entityType in model.GetEntityTypes())
            {
                if (InMemoryEntityTypeExtensions.GetDefiningQuery(entityType) != null)
                {
                    if (entityType.BaseType != null)
                    {
                        throw new InvalidOperationException(
                                  CoreStrings.DerivedTypeDefiningQuery(entityType.DisplayName(), entityType.BaseType.DisplayName()));
                    }
                }
            }
        }