/// <inheritdoc />
        public virtual string GetMethodChain(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");
            Debug.Assert(_properties.Count != 0, "_properties is empty.");

            return ".HasForeignKey(" + code.Lambda(_properties) + ")";
        }
        /// <inheritdoc />
        public virtual string GetMethodChain(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");
            Debug.Assert(Name != null || TypeName != null || Order != null, "Name, TypeName & Order are null.");

            var builder = new StringBuilder();

            if (Name != null)
            {
                builder.Append(".HasColumnName(");
                builder.Append(code.Literal(Name));
                builder.Append(")");
            }

            if (Order.HasValue)
            {
                builder.Append(".HasColumnOrder(");
                builder.Append(code.Literal(Order.Value));
                builder.Append(")");
            }

            if (TypeName != null)
            {
                builder.Append(".HasColumnType(");
                builder.Append(code.Literal(TypeName));
                builder.Append(")");
            }

            return builder.ToString();
        }
        /// <inheritdoc />
        public virtual string GetMethodChain(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");
            Debug.Assert(!string.IsNullOrEmpty(Table), "Table is null or empty.");

            return ".ToTable(" + code.Literal(GetName()) + ")";
        }
        // Internal for testing
        internal TableDiscoverer(CodeHelper code, IPluralizationService pluralizationService)
        {
            Debug.Assert(code != null, "code is null.");
            Debug.Assert(pluralizationService != null, "pluralizationService is null.");

            _code = code;
            _pluralizationService = pluralizationService;
        }
        /// <inheritdoc />
        public virtual string GetAttributeBody(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");

            return "DatabaseGenerated(DatabaseGeneratedOption."
                + StoreGeneratedPattern.ToDatabaseGeneratedOption()
                + ")";
        }
        // Internal for testing
        internal ColumnDiscoverer(CodeHelper code, IDbDependencyResolver dependencyResolver)
        {
            Debug.Assert(code != null, "code is null.");
            Debug.Assert(dependencyResolver != null, "dependencyResolver is null.");

            _code = code;
            _dependencyResolver = dependencyResolver;
        }
        /// <inheritdoc />
        public virtual string GetMethodChain(CodeHelper code)
        {
            // TODO: Throw instead?
            Debug.Assert(code != null, "code is null.");
            Debug.Assert(_keyProperties.Count != 0, "_keyProperties is empty.");

            return ".HasKey(" + code.Lambda(_keyProperties) + ")";
        }
        /// <inheritdoc />
        public virtual string GetMethodChain(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");

            return ".HasDatabaseGeneratedOption(DatabaseGeneratedOption."
                + StoreGeneratedPattern.ToDatabaseGeneratedOption()
                + ")";
        }
        /// <inheritdoc />
        public virtual string GetMethodChain(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");
            Debug.Assert(
                Table != null || _leftKeys.Any() || _rightKeys.Any(),
                "Table is null and _leftKeys and _rightKeys are empty.");

            var builder = new StringBuilder();
            builder.Append(".Map(");
            builder.Append(code.BeginLambda("m"));
            builder.Append("m");

            if (Table != null)
            {
                builder.Append(".ToTable(");
                builder.Append(code.Literal(Table));

                if (Schema != null)
                {
                    builder.Append(", ");
                    builder.Append(code.Literal(Schema));
                }

                builder.Append(")");
            }

            if (_leftKeys.Count != 0)
            {
                builder.Append(".MapLeftKey(");
                builder.Append(code.Literal(_leftKeys));
                builder.Append(")");
            }

            if (_rightKeys.Count != 0)
            {
                builder.Append(".MapRightKey(");
                builder.Append(code.Literal(_rightKeys));
                builder.Append(")");
            }

            builder.Append(")");

            return builder.ToString();
        }
        /// <inheritdoc />
        public virtual string GetMethodChain(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");

            var builder = new StringBuilder();

            builder.Append(".WillCascadeOnDelete(");

            if (DeleteBehavior != OperationAction.Cascade)
            {
                Debug.Assert(DeleteBehavior == OperationAction.None, "DeleteBehavior is not None.");

                builder.Append(code.Literal(false));
            }

            builder.Append(")");

            return builder.ToString();
        }
        /// <inheritdoc />
        public virtual string GetAttributeBody(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");
            Debug.Assert(Name != null || TypeName != null || Order != null, "Name, TypeName & Order are null.");

            var builder = new StringBuilder();
            builder.Append("Column(");

            if (Name != null)
            {
                builder.Append(code.Literal(Name));
            }

            if (Order.HasValue)
            {
                if (Name != null)
                {
                    builder.Append(", ");
                }

                builder.Append("Order");
                builder.Append(code.NamedParameterSetter);
                builder.Append(code.Literal(Order.Value));
            }

            if (TypeName != null)
            {
                if (Name != null || Order.HasValue)
                {
                    builder.Append(", ");
                }

                builder.Append("TypeName");
                builder.Append(code.NamedParameterSetter);
                builder.Append(code.Literal(TypeName));
            }

            builder.Append(")");

            return builder.ToString();
        }
Exemple #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EdmHelper"/> class.
        /// </summary>
        /// <param name="code">The helper used to generate code.</param>
        public EdmHelper(CodeHelper code)
        {
            _typeConfigurationDiscoverers = new ITypeConfigurationDiscoverer[]
                {
                    new KeyDiscoverer(),
                    new TableDiscoverer(code)
                };

            _propertyConfigurationDiscoverers = new IPropertyConfigurationDiscoverer[]
                {
                    new KeyPropertyDiscoverer(),                    
                    new ColumnDiscoverer(code),
                    new DatabaseGeneratedDiscoverer(),
                    new PrecisionDateTimeDiscoverer(),
                    new PrecisionDecimalDiscoverer(),
                    new RequiredDiscoverer(),
                    new MaxLengthDiscoverer(),
                    new TimestampDiscoverer(),                    
                    new FixedLengthDiscoverer(),
                    new NonUnicodeDiscoverer()
                };
        }
        /// <inheritdoc />
        public virtual string GetAttributeBody(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");

            return "Key";
        }
        /// <inheritdoc />
        public virtual string GetMethodChain(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");

            return ".HasPrecision(" + code.Literal(Precision) + ", " + code.Literal(Scale) + ")";
        }
        /// <inheritdoc />
        // TODO: Handle formatting elsewhere
        public virtual string GetMethodChain(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");
            Debug.Assert(LeftEntityType != null, "LeftEntityType is null.");
            Debug.Assert(LeftNavigationProperty != null, "LeftNavigationProperty is null.");
            Debug.Assert(RightNavigationProperty != null, "RightNavigationProperty is null.");

            var builder = new StringBuilder();
            builder.Append(".Entity");
            builder.Append(code.TypeArgument(code.Type(LeftEntityType)));
            builder.AppendLine("()");

            var rightMultiplicity = RightNavigationProperty.FromEndMember.RelationshipMultiplicity;

            switch (rightMultiplicity)
            {
                case RelationshipMultiplicity.Many:
                    builder.Append("                .HasMany(");
                    builder.Append(code.Lambda(LeftNavigationProperty));
                    builder.Append(")");
                    break;

                case RelationshipMultiplicity.One:
                    builder.Append("                .HasRequired(");
                    builder.Append(code.Lambda(LeftNavigationProperty));
                    builder.Append(")");
                    break;

                case RelationshipMultiplicity.ZeroOrOne:
                    builder.Append("                .HasOptional(");
                    builder.Append(code.Lambda(LeftNavigationProperty));
                    builder.Append(")");
                    break;

                default:
                    Debug.Fail("rightMultiplicity is not a valid RelationshipMultiplicity value.");
                    break;
            }

            builder.AppendLine();

            switch (LeftNavigationProperty.FromEndMember.RelationshipMultiplicity)
            {
                case RelationshipMultiplicity.Many:
                    builder.Append("                .WithMany(");
                    builder.Append(code.Lambda(RightNavigationProperty));
                    builder.Append(")");
                    break;

                case RelationshipMultiplicity.One:
                    Debug.Assert(rightMultiplicity != RelationshipMultiplicity.One, "rightMultiplicity is One.");
                    builder.Append("                .WithRequired(");
                    builder.Append(code.Lambda(RightNavigationProperty));
                    builder.Append(")");
                    break;

                case RelationshipMultiplicity.ZeroOrOne:
                    Debug.Assert(
                        rightMultiplicity != RelationshipMultiplicity.ZeroOrOne,
                        "rightMultiplicity is ZeroOrOne.");
                    builder.Append("                .WithOptional(");
                    builder.Append(code.Lambda(RightNavigationProperty));
                    builder.Append(")");
                    break;

                default:
                    Debug.Fail("LeftNavigationProperty.FromEndMember.RelationshipMultiplicity is not a valid RelationshipMultiplicity value.");
                    break;
            }

            return builder.ToString();
        }
 public TableDiscoverer(CodeHelper code)
     : this(code, DependencyResolver.GetService<IPluralizationService>())
 {
     Debug.Assert(code != null, "code is null.");
 }
        /// <inheritdoc />
        public virtual string GetMethodChain(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");

            return ".HasMaxLength(" + code.Literal(MaxLength) + ")";
        }
        /// <inheritdoc />
        public virtual string GetMethodChain(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");

            return(".IsFixedLength()");
        }
        /// <inheritdoc />
        public virtual string GetMethodChain(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");

            return(".IsRowVersion()");
        }
        /// <inheritdoc />
        public virtual string GetAttributeBody(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");

            return("Timestamp");
        }
        /// <inheritdoc />
        public virtual string GetMethodChain(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");

            return ".IsFixedLength()";
        }
Exemple #22
0
 public ColumnDiscoverer(CodeHelper code)
     : this(code, DependencyResolver.Instance)
 {
     Debug.Assert(code != null, "code is null.");
 }
        /// <inheritdoc />
        public override string GetAttributeBody(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");

            return "StringLength(" + code.Literal(MaxLength) + ")";
        }
        /// <inheritdoc />
        public virtual string GetMethodChain(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");

            return ".IsRowVersion()";
        }
        /// <inheritdoc />
        public override string GetAttributeBody(CodeHelper code)
        {
            Debug.Assert(code != null, "code is null.");

            return("StringLength(" + code.Literal(MaxLength) + ")");
        }
 public ColumnDiscoverer(CodeHelper code)
     : this(code, DependencyResolver.Instance)
 {
     Debug.Assert(code != null, "code is null.");
 }