Exemplo n.º 1
0
        /// <summary>
        /// Configures the primary key property(s) for this entity type.
        /// </summary>
        /// <typeparam name="TKey"> The type of the key. </typeparam>
        /// <param name="keyExpression"> A lambda expression representing the property to be used as the primary key.
        /// C#: t => t.Id VB.Net: Function(t) t.Id
        /// If the primary key is made up of multiple properties then specify an anonymous type including the properties.
        /// C#: t => new { t.Id1, t.Id2 } VB.Net: Function(t) New With { t.Id1, t.Id2 } </param>
        /// <returns> The same EntityTypeConfiguration instance so that multiple calls can be chained. </returns>
        public EntityTypeConfiguration <TEntityType> HasKey <TKey>(Expression <Func <TEntityType, TKey> > keyExpression)
        {
            if (keyExpression == null)
            {
                throw new ArgumentNullException("keyExpression");
            }

            primaryKeyProperty = ReflectionExpressions.GetPropertyInfo(keyExpression);
            return(this);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Configures the relationship to use foreign key property(s) that are exposed in the object model.
        /// If the foreign key property(s) are not exposed in the object model then use the Map method.
        /// </summary>
        /// <typeparam name="TKey"> The type of the key. </typeparam>
        /// <param name="foreignKeyExpression"> A lambda expression representing the property to be used as the foreign key. If the foreign key is made up of multiple properties then specify an anonymous type including the properties. When using multiple foreign key properties, the properties must be specified in the same order that the the primary key properties were configured for the principal entity type. </param>
        /// <returns> A configuration object that can be used to further configure the relationship. </returns>
        public CascadableNavigationPropertyConfiguration HasForeignKey <TKey>(
            Expression <Func <TDependentEntityType, TKey> > foreignKeyExpression)
        {
            if (foreignKeyExpression == null)
            {
                throw new ArgumentNullException("foreignKeyExpression");
            }

            foreignKeyProperty = ReflectionExpressions.GetPropertyInfo(foreignKeyExpression);
            return(this);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Configures a <see cref="T:System.byte[]" /> property that is defined on this type.
        /// </summary>
        /// <param name="propertyExpression"> A lambda expression representing the property to be configured. C#: t => t.MyProperty VB.Net: Function(t) t.MyProperty </param>
        /// <returns> A configuration object that can be used to configure the property. </returns>
        public BinaryPropertyConfiguration Property(Expression <Func <TStructuralType, byte[]> > propertyExpression)
        {
            if (propertyExpression == null)
            {
                throw new ArgumentNullException("propertyExpression");
            }

            var property = ReflectionExpressions.GetPropertyInfo(propertyExpression);
            PrimitivePropertyConfiguration propertyConfiguration;

            if (!PropertyConfigurationsByProperty.TryGetValue(property, out propertyConfiguration))
            {
                propertyConfiguration = new BinaryPropertyConfiguration(property);
                PropertyConfigurationsByProperty.Add(property, propertyConfiguration);
            }
            return((BinaryPropertyConfiguration)propertyConfiguration);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Configures a required relationship from this entity type.
        /// Instances of the entity type will not be able to be saved to the database unless this relationship is specified.
        /// The foreign key in the database will be non-nullable.
        /// </summary>
        /// <typeparam name="TTargetEntity"> The type of the entity at the other end of the relationship. </typeparam>
        /// <param name="navigationPropertyExpression"> A lambda expression representing the navigation property
        /// for the relationship. C#: t => t.MyProperty VB.Net: Function(t) t.MyProperty </param>
        /// <returns> A configuration object that can be used to further configure the relationship. </returns>
        public RequiredNavigationPropertyConfiguration <TEntityType, TTargetEntity> HasRequired <TTargetEntity>(
            Expression <Func <TEntityType, TTargetEntity> > navigationPropertyExpression)
            where TTargetEntity : class
        {
            if (navigationPropertyExpression == null)
            {
                throw new ArgumentNullException("navigationPropertyExpression");
            }

            var navigationProperty = ReflectionExpressions.GetPropertyInfo(navigationPropertyExpression);
            IRequiredNavigationPropertyConfiguration propertyConfiguration;

            if (!requiredAssociationsByProperty.TryGetValue(navigationProperty, out propertyConfiguration))
            {
                propertyConfiguration =
                    new RequiredNavigationPropertyConfiguration <TEntityType, TTargetEntity>(navigationProperty);
                requiredAssociationsByProperty.Add(navigationProperty, propertyConfiguration);
            }
            return((RequiredNavigationPropertyConfiguration <TEntityType, TTargetEntity>)propertyConfiguration);
        }