Exemplo n.º 1
0
        /// <summary>
        ///     <para>
        ///         Returns a fluent API call for the given <paramref name="annotation" />, or <see langword="null" />
        ///         if no fluent API call exists for it.
        ///     </para>
        ///     <para>
        ///         The default implementation always returns <see langword="null" />.
        ///     </para>
        /// </summary>
        /// <param name="navigation">The <see cref="ISkipNavigation" />.</param>
        /// <param name="annotation">The <see cref="IAnnotation" />.</param>
        /// <returns><see langword="null" />.</returns>
        protected virtual MethodCallCodeFragment?GenerateFluentApi(ISkipNavigation navigation, IAnnotation annotation)
        {
            Check.NotNull(navigation, nameof(navigation));
            Check.NotNull(annotation, nameof(annotation));

            return(null);
        }
Exemplo n.º 2
0
 /// <summary>
 ///     Constructs the event payload.
 /// </summary>
 /// <param name="eventDefinition"> The event definition. </param>
 /// <param name="messageGenerator"> A delegate that generates a log message for this event. </param>
 /// <param name="navigation"> The navigation. </param>
 public SkipNavigationEventData(
     [NotNull] EventDefinitionBase eventDefinition,
     [NotNull] Func <EventDefinitionBase, EventData, string> messageGenerator,
     [NotNull] ISkipNavigation navigation)
     : base(eventDefinition, messageGenerator)
 {
     Navigation = navigation;
 }
        /// <inheritdoc />
        public virtual IReadOnlyList <MethodCallCodeFragment> GenerateFluentApiCalls(
            ISkipNavigation navigation,
            IDictionary <string, IAnnotation> annotations)
        {
            var methodCallCodeFragments = new List <MethodCallCodeFragment>();

            methodCallCodeFragments.AddRange(GenerateFluentApiCallsHelper(navigation, annotations, GenerateFluentApi));

            return(methodCallCodeFragments);
        }
Exemplo n.º 4
0
 private void GenerateForeignKeyAttribute(ISkipNavigation navigation)
 {
     if (navigation.ForeignKey.PrincipalKey.IsPrimaryKey())
     {
         var foreignKeyAttribute = new AttributeWriter(nameof(ForeignKeyAttribute));
         foreignKeyAttribute.AddParameter(
             _code.Literal(
                 string.Join(",", navigation.ForeignKey.Properties.Select(p => p.Name))));
         _sb.AppendLine(foreignKeyAttribute.ToString());
     }
 }
Exemplo n.º 5
0
        /// <inheritdoc />
        public virtual void Generate(ISkipNavigation navigation, CSharpRuntimeAnnotationCodeGeneratorParameters parameters)
        {
            if (!parameters.IsRuntime)
            {
                var annotations = parameters.Annotations;
                annotations.Remove(CoreAnnotationNames.PropertyAccessMode);
                annotations.Remove(CoreAnnotationNames.EagerLoaded);
            }

            GenerateSimpleAnnotations(parameters);
        }
Exemplo n.º 6
0
 /// <summary>
 ///     Constructs the event payload.
 /// </summary>
 /// <param name="eventDefinition">The event definition.</param>
 /// <param name="messageGenerator">A delegate that generates a log message for this event.</param>
 /// <param name="entityEntry">The entry for the entity instance on which the property value has changed.</param>
 /// <param name="navigation">The navigation property.</param>
 /// <param name="added">The entities added to the collection.</param>
 /// <param name="removed">The entities removed from the collection.</param>
 public SkipCollectionChangedEventData(
     EventDefinitionBase eventDefinition,
     Func <EventDefinitionBase, EventData, string> messageGenerator,
     EntityEntry entityEntry,
     ISkipNavigation navigation,
     IEnumerable <object> added,
     IEnumerable <object> removed)
     : base(eventDefinition, messageGenerator, navigation)
 {
     EntityEntry = entityEntry;
     Added       = added;
     Removed     = removed;
 }
    private void GenerateInversePropertyAttribute(ISkipNavigation navigation)
    {
        if (navigation.ForeignKey.PrincipalKey.IsPrimaryKey())
        {
            var inverseNavigation = navigation.Inverse;

            if (inverseNavigation != null)
            {
                var inversePropertyAttribute = new AttributeWriter(nameof(InversePropertyAttribute));

                inversePropertyAttribute.AddParameter(_code.Literal(inverseNavigation.Name));

                _sb.AppendLine(inversePropertyAttribute.ToString());
            }
        }
    }
Exemplo n.º 8
0
    /// <inheritdoc />
    public virtual void Generate(ISkipNavigation navigation, CSharpRuntimeAnnotationCodeGeneratorParameters parameters)
    {
        if (!parameters.IsRuntime)
        {
            var annotations = parameters.Annotations;
            foreach (var(key, _) in annotations)
            {
                if (CoreAnnotationNames.AllNames.Contains(key))
                {
                    annotations.Remove(key);
                }
            }
        }

        GenerateSimpleAnnotations(parameters);
    }
Exemplo n.º 9
0
        /// <summary>
        ///     Constructs the event payload.
        /// </summary>
        /// <param name="eventDefinition"> The event definition. </param>
        /// <param name="messageGenerator"> A delegate that generates a log message for this event. </param>
        /// <param name="entityEntry"> The entry for the entity instance on which the property value has changed. </param>
        /// <param name="navigation"> The navigation property. </param>
        /// <param name="added"> The entities added to the collection. </param>
        /// <param name="removed"> The entities removed from the collection. </param>
        public SkipCollectionChangedEventData(
            [NotNull] EventDefinitionBase eventDefinition,
            [NotNull] Func <EventDefinitionBase, EventData, string> messageGenerator,
            [NotNull] EntityEntry entityEntry,
            [NotNull] ISkipNavigation navigation,
            [NotNull] IEnumerable <object> added,
            [NotNull] IEnumerable <object> removed)
            : base(eventDefinition, messageGenerator, navigation)
        {
            Check.NotNull(entityEntry, nameof(entityEntry));
            Check.NotNull(added, nameof(added));
            Check.NotNull(removed, nameof(removed));

            EntityEntry = entityEntry;
            Added       = added;
            Removed     = removed;
        }
Exemplo n.º 10
0
        private static Expression <Func <TEntity, IEnumerable <TSourceEntity> > > BuildIncludeLambda(
            ISkipNavigation skipNavigation,
            IReadOnlyList <IProperty> keyProperties,
            ValueBuffer keyValues)
        {
            var whereParameter  = Expression.Parameter(typeof(TSourceEntity), "e");
            var entityParameter = Expression.Parameter(typeof(TEntity), "e");

            return(Expression.Lambda <Func <TEntity, IEnumerable <TSourceEntity> > >(
                       Expression.Call(
                           EnumerableMethods.Where.MakeGenericMethod(typeof(TSourceEntity)),
                           Expression.MakeMemberAccess(
                               entityParameter,
                               skipNavigation.PropertyInfo),
                           Expression.Lambda <Func <TSourceEntity, bool> >(
                               ExpressionExtensions.BuildPredicate(keyProperties, keyValues, whereParameter),
                               whereParameter)), entityParameter));
        }
Exemplo n.º 11
0
        private void GenerateInversePropertyAttribute(ISkipNavigation navigation)
        {
            if (navigation.ForeignKey.PrincipalKey.IsPrimaryKey())
            {
                var inverseNavigation = navigation.Inverse;

                if (inverseNavigation != null)
                {
                    var inversePropertyAttribute = new AttributeWriter(nameof(InversePropertyAttribute));

                    inversePropertyAttribute.AddParameter(
                        !navigation.DeclaringEntityType.GetPropertiesAndNavigations().Any(
                            m => m.Name == inverseNavigation.DeclaringEntityType.Name)
                            ? $"nameof({inverseNavigation.DeclaringEntityType.Name}.{inverseNavigation.Name})"
                            : _code.Literal(inverseNavigation.Name));

                    _sb.AppendLine(inversePropertyAttribute.ToString());
                }
            }
        }
 /// <summary>
 ///     Returns a fluent API call for the given <paramref name="annotation" />, or <see langword="null" />
 ///     if no fluent API call exists for it.
 /// </summary>
 /// <remarks>
 ///     The default implementation always returns <see langword="null" />.
 /// </remarks>
 /// <param name="navigation">The <see cref="ISkipNavigation" />.</param>
 /// <param name="annotation">The <see cref="IAnnotation" />.</param>
 /// <returns><see langword="null" />.</returns>
 protected virtual MethodCallCodeFragment?GenerateFluentApi(ISkipNavigation navigation, IAnnotation annotation)
 => null;
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public static MemberIdentity CreateMemberIdentity([CanBeNull] this ISkipNavigation navigation)
 => navigation?.GetIdentifyingMemberInfo() == null
         ? MemberIdentity.Create(navigation?.Name)
         : MemberIdentity.Create(navigation.GetIdentifyingMemberInfo());
Exemplo n.º 14
0
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public ManyToManyLoader([NotNull] ISkipNavigation skipNavigation)
 {
     _skipNavigation = skipNavigation;
 }
Exemplo n.º 15
0
        /// <summary>
        ///     <para>
        ///         Creates a human-readable representation of the given metadata.
        ///     </para>
        ///     <para>
        ///         Warning: Do not rely on the format of the returned string.
        ///         It is designed for debugging only and may change arbitrarily between releases.
        ///     </para>
        /// </summary>
        /// <param name="navigation"> The metadata item. </param>
        /// <param name="options"> Options for generating the string. </param>
        /// <param name="indent"> The number of indent spaces to use before each new line. </param>
        /// <returns> A human-readable representation. </returns>
        public static string ToDebugString(
            [NotNull] this ISkipNavigation navigation,
            MetadataDebugStringOptions options,
            int indent = 0)
        {
            var builder      = new StringBuilder();
            var indentString = new string(' ', indent);

            builder.Append(indentString);

            var singleLine = (options & MetadataDebugStringOptions.SingleLine) != 0;

            if (singleLine)
            {
                builder.Append($"SkipNavigation: {navigation.DeclaringEntityType.DisplayName()}.");
            }

            builder.Append(navigation.Name);

            var field = navigation.GetFieldName();

            if (field == null)
            {
                builder.Append(" (no field, ");
            }
            else if (!field.EndsWith(">k__BackingField", StringComparison.Ordinal))
            {
                builder.Append($" ({field}, ");
            }
            else
            {
                builder.Append(" (");
            }

            builder.Append(navigation.ClrType?.ShortDisplayName()).Append(")");

            if (navigation.IsCollection)
            {
                builder.Append(" Collection");
            }

            builder.Append(navigation.TargetEntityType.DisplayName());

            if (navigation.Inverse != null)
            {
                builder.Append(" Inverse: ").Append(navigation.Inverse.Name);
            }

            if (navigation.GetPropertyAccessMode() != PropertyAccessMode.PreferField)
            {
                builder.Append(" PropertyAccessMode.").Append(navigation.GetPropertyAccessMode());
            }

            if ((options & MetadataDebugStringOptions.IncludePropertyIndexes) != 0)
            {
                var indexes = navigation.GetPropertyIndexes();
                builder.Append(" ").Append(indexes.Index);
                builder.Append(" ").Append(indexes.OriginalValueIndex);
                builder.Append(" ").Append(indexes.RelationshipIndex);
                builder.Append(" ").Append(indexes.ShadowIndex);
                builder.Append(" ").Append(indexes.StoreGenerationIndex);
            }

            if (!singleLine &&
                (options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
            {
                builder.Append(navigation.AnnotationsToDebugString(indent + 2));
            }

            return(builder.ToString());
        }
 public static ICollectionLoader GetManyToManyLoader([NotNull] this ISkipNavigation navigation)
 => ((SkipNavigation)navigation).ManyToManyLoader;
Exemplo n.º 17
0
 private void GenerateNavigationDataAnnotations(ISkipNavigation navigation)
 {
     GenerateForeignKeyAttribute(navigation);
     GenerateInversePropertyAttribute(navigation);
 }
Exemplo n.º 18
0
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public virtual ICollectionLoader Create(ISkipNavigation skipNavigation)
 => (ICollectionLoader)_genericCreate.MakeGenericMethod(
     skipNavigation.TargetEntityType.ClrType,
     skipNavigation.DeclaringEntityType.ClrType)
 .Invoke(null, new object[] { skipNavigation }) !;
Exemplo n.º 19
0
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public virtual IClrCollectionAccessor Create([NotNull] ISkipNavigation navigation)
 => !navigation.IsCollection || navigation.IsShadowProperty() ? null : Create(navigation, navigation.TargetEntityType);
Exemplo n.º 20
0
 private static ICollectionLoader CreateManyToMany <TEntity, TTargetEntity>(ISkipNavigation skipNavigation)
     where TEntity : class
     where TTargetEntity : class
 => new ManyToManyLoader <TEntity, TTargetEntity>(skipNavigation);
Exemplo n.º 21
0
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public ManyToManyLoader(ISkipNavigation skipNavigation)
 {
     _skipNavigation = skipNavigation;
 }