Esempio n. 1
0
 public override string ToString()
 {
     return(string.Format(
                CultureInfo.CurrentCulture,
                "'{0}' {1} -> '{2}' {3}",
                EntityType.DisplayName(),
                Property.Format(Properties),
                PrincipalEntityType.DisplayName(),
                Property.Format(PrincipalKey.Properties)));
 }
        protected virtual bool SetDiscriminatorValue([CanBeNull] object value)
        {
            if (DiscriminatorProperty == null)
            {
                throw new InvalidOperationException(
                          RelationalStrings.NoDiscriminatorForValue(EntityType.DisplayName(), EntityType.RootType().DisplayName()));
            }

            if (value != null && !DiscriminatorProperty.ClrType.GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo()))
            {
                throw new InvalidOperationException(RelationalStrings.DiscriminitatorValueIncompatible(
                                                        value, DiscriminatorProperty.Name, DiscriminatorProperty.ClrType));
            }

            return(Annotations.SetAnnotation(RelationalAnnotationNames.DiscriminatorValue, value));
        }
Esempio n. 3
0
 public override string ToString()
 => $"'{EntityType.DisplayName()}' {Property.Format(Properties)} -> '{PrincipalEntityType.DisplayName()}' {Property.Format(PrincipalKey.Properties)}";
Esempio n. 4
0
        public static bool CanPropertiesBeRequired(
            [NotNull] IEnumerable <Property> properties,
            bool?required,
            [NotNull] EntityType entityType,
            bool shouldThrow)
        {
            Check.NotNull(properties, nameof(properties));
            Check.NotNull(entityType, nameof(entityType));

            if (!required.HasValue ||
                required.Value)
            {
                return(true);
            }

            var nullableProperties = properties.Where(p => ((IProperty)p).ClrType.IsNullableType()).ToList();

            if (!nullableProperties.Any())
            {
                if (shouldThrow)
                {
                    throw new InvalidOperationException(CoreStrings.ForeignKeyCannotBeOptional(
                                                            Property.Format(properties), entityType.DisplayName()));
                }
                return(false);
            }

            return(true);
        }