Exemple #1
0
 void IMetadataBuilder.BuildAssociationMetadata(AssociationMetadata metadata, MethodBuilder methodBuilder)
 {
     BuildAssociationAttribute(metadata, methodBuilder.Attribute(WellKnownTypes.LinqToDB.Mapping.AssociationAttribute));
 }
Exemple #2
0
        /// <summary>
        /// Generates <see cref="AssociationAttribute"/> on association property or method.
        /// </summary>
        /// <param name="metadata">Association metadata descriptor.</param>
        /// <param name="attr">Association attribute builder.</param>
        private void BuildAssociationAttribute(AssociationMetadata metadata, AttributeBuilder attr)
        {
            if (!metadata.CanBeNull)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Mapping.AssociationAttribute_CanBeNull, _builder.Constant(false, true));
            }

            // track association is configured to avoid generation of multiple conflicting configurations
            // as assocation could be configured in several ways
            var associationConfigured = false;

            if (metadata.ExpressionPredicate != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Mapping.AssociationAttribute_ExpressionPredicate, _builder.Constant(metadata.ExpressionPredicate, true));
                associationConfigured = true;
            }

            if (metadata.QueryExpressionMethod != null)
            {
                if (associationConfigured)
                {
                    throw new InvalidOperationException("Association contains multiple relation setups");
                }

                attr.Parameter(WellKnownTypes.LinqToDB.Mapping.AssociationAttribute_QueryExpressionMethod, _builder.Constant(metadata.QueryExpressionMethod, true));
                associationConfigured = true;
            }

            // track setup status of by-column assocation mapping
            var thisConfigured  = false;
            var otherConfigured = false;

            if (metadata.ThisKeyExpression != null)
            {
                if (associationConfigured || metadata.ThisKey != null)
                {
                    throw new InvalidOperationException("Association contains multiple relation setups");
                }

                attr.Parameter(WellKnownTypes.LinqToDB.Mapping.AssociationAttribute_ThisKey, metadata.ThisKeyExpression);

                thisConfigured = true;
            }

            if (metadata.OtherKeyExpression != null)
            {
                if (associationConfigured || metadata.OtherKey != null)
                {
                    throw new InvalidOperationException("Association contains multiple relation setups");
                }

                attr.Parameter(WellKnownTypes.LinqToDB.Mapping.AssociationAttribute_OtherKey, metadata.OtherKeyExpression);

                otherConfigured = true;
            }

            if (metadata.ThisKey != null)
            {
                if (associationConfigured || thisConfigured)
                {
                    throw new InvalidOperationException("Association contains multiple relation setups");
                }

                attr.Parameter(WellKnownTypes.LinqToDB.Mapping.AssociationAttribute_ThisKey, _builder.Constant(metadata.ThisKey, true));
                thisConfigured = true;
            }

            if (metadata.OtherKey != null)
            {
                if (associationConfigured || otherConfigured)
                {
                    throw new InvalidOperationException("Association contains multiple relation setups");
                }

                attr.Parameter(WellKnownTypes.LinqToDB.Mapping.AssociationAttribute_OtherKey, _builder.Constant(metadata.OtherKey, true));
                otherConfigured = true;
            }

            if (!associationConfigured && !(thisConfigured && otherConfigured))
            {
                throw new InvalidOperationException("Association is missing relation setup");
            }

            if (metadata.Configuration != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Mapping.AssociationAttribute_Configuration, _builder.Constant(metadata.Configuration, true));
            }
            if (metadata.Alias != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Mapping.AssociationAttribute_AliasName, _builder.Constant(metadata.Alias, true));
            }
            if (metadata.Storage != null)
            {
                attr.Parameter(WellKnownTypes.LinqToDB.Mapping.AssociationAttribute_Storage, _builder.Constant(metadata.Storage, true));
            }
        }
Exemple #3
0
 void IMetadataBuilder.BuildAssociationMetadata(AssociationMetadata metadata, PropertyBuilder propertyBuilder)
 {
     BuildAssociationAttribute(metadata, propertyBuilder.AddAttribute(WellKnownTypes.LinqToDB.Mapping.AssociationAttribute));
 }