示例#1
0
 public override IModelNode VisitField <T>(IModelFieldOf <T> field)
 {
     return(new ValueNode
     {
         Value = ((SqlStorageField <TEntity, T>)field).DefaultValue()
     });
 }
示例#2
0
        public IModelNode VisitField <T>(IModelFieldOf <T> field)
        {
            var propertyField = field as PropertyField;

            if (propertyField == null)
            {
                return(null);
            }

            if (_joinSpecification != null)
            {
                return(new ForeignSqlStorageField <TEntity, TForeignEntity, T>(
                           string.Join("_", _currentPath), true, true,
                           _sqlFieldConfiguration.Options.IsServerGenerated,
                           _sqlFieldConfiguration.Options.ColumnName,
                           null,
                           _sqlFieldConfiguration.Options.IsPrimaryKey,
                           new FieldGraphPath <PropertyField>(_currentPath.ToArray(), propertyField),
                           _joinSpecification));
            }

            return(new ForeignKeySqlStorageField <TEntity, TForeignEntity, T>(
                       string.Join("_", _currentPath), true, true,
                       _sqlFieldConfiguration.Options.IsServerGenerated,
                       _sqlFieldConfiguration.Options.ColumnName,
                       null,
                       _sqlFieldConfiguration.Options.IsPrimaryKey,
                       new FieldGraphPath <PropertyField>(_currentPath.ToArray(), propertyField)));
        }
 public BindingTargetVisitor(
     IModelFieldOf <TSource> source,
     IBindingTransformFactory transformFactory
     )
 {
     _source           = source;
     _transformFactory = transformFactory;
 }
            public override IModelNode VisitField <T>(IModelFieldOf <T> field)
            {
                var subVisitor = new BindingTargetVisitor <T>(field, _transformFactory);

                _target.Accept(subVisitor);
                Result = subVisitor.Result;
                return(base.VisitField(field));
            }
示例#5
0
            public BindingTransformation CreateTransformation <TSource1, TTarget1>(
                IModelFieldOf <TSource1> sourceField, IModelFieldOf <TTarget1> targetField)
            {
                var convertDelegate = _tryConvertDelegate;

                return((BindingContext context, object @in, out object @out) =>
                {
                    var result = convertDelegate((TFrom)@in, out var convertedValue);
                    @out = convertedValue;
                    return result;
                });
            }
示例#6
0
            public IModelNode VisitField <T>(IModelFieldOf <T> field)
            {
                var currentPath   = _currentPath;
                var propertyField = field as PropertyField;

                if (propertyField == null)
                {
                    return(null);
                }

                return(new SqlEntityField <TEntity, T>(
                           field.FieldName, field.CanWrite, field.CanRead,
                           propertyField.Property,
                           new FieldGraphPath <PropertyField>(_currentPath.ToArray(), propertyField)
                           ));
            }
示例#7
0
            public BindingTransformation CreateTransformation <TSource, TTarget>(IModelFieldOf <TSource> sourceField, IModelFieldOf <TTarget> targetField)
            {
                var tryParseMethod = _explicitCastMethod;

                var fromParameter = Expression.Parameter(typeof(TSource), "from");
                var toParameter   = Expression.Parameter(typeof(TTarget).MakeByRefType(), "to");

                var lambda = Expression.Lambda <BindingTransformation>(
                    Expression.Block(
                        Expression.Assign(toParameter, Expression.Call(_explicitCastMethod, fromParameter)),
                        Expression.Constant(true)
                        ), fromParameter, toParameter
                    );

                return(lambda.Compile());
            }
示例#8
0
        public IModelNode VisitField <T>(IModelFieldOf <T> field)
        {
            var currentPath   = _currentPath;
            var propertyField = field as PropertyField;

            if (propertyField == null)
            {
                return(null);
            }

            var fieldConfiguration = FindLocalFieldConfiguration <T>(currentPath);

            if (fieldConfiguration != null)
            {
                var localStorageNode = CreateLocalStorageField <T>(fieldConfiguration, currentPath, field);
                if (fieldConfiguration.Options.IsForeignKey)
                {
                    var entityBuilder = _buildContext.SqlBuilders.FirstOrDefault(q => q.EntityType == typeof(T));
                    if (entityBuilder != null)
                    {
                        return(new ModelStateNode(localStorageNode, new ModelState <T>(entityBuilder, currentPath.ToArray(),
                                                                                       localStorageNode as SqlStorageField <TEntity>)));
                    }
                }
                return(new ModelStateNode(localStorageNode, null));
            }

            fieldConfiguration = FindForeignFieldConfiguration <T>(currentPath);
            if (fieldConfiguration != null)
            {
                var foreignStorageNode = _modelStateStack.Peek()
                                         .CreateForeignStorageField <T>(fieldConfiguration, currentPath, field);
                if (fieldConfiguration.Options.IsForeignKey)
                {
                    var entityBuilder = _buildContext.SqlBuilders.FirstOrDefault(q => q.EntityType == typeof(T));
                    return(new ModelStateNode(foreignStorageNode, new ModelState <T>(entityBuilder, currentPath.ToArray(),
                                                                                     foreignStorageNode as SqlStorageField <TEntity>)));
                }
                return(new ModelStateNode(foreignStorageNode, null));
            }

            return(default(ModelStateNode));
        }
示例#9
0
        private IModelNode CreateLocalStorageField <T>(SqlFieldConfiguration <T> fieldConfiguration, IEnumerable <string> path,
                                                       IModelFieldOf <T> field)
        {
            if (fieldConfiguration.Options.IsForeignKey)
            {
                //  todo: the pattern employed here only permits one foreign key to entities
                //    to support more complex foreign key relationships this needs to be adjusted
                return(new ForeignKeyVisitor <TEntity, T>(_currentPath, fieldConfiguration)
                       .Visit(fieldConfiguration.Options.ForeignKeyFieldPath.Field));
            }

            return(new SqlStorageField <TEntity, T>(
                       string.Join("_", path), true, true,
                       fieldConfiguration.Options.IsServerGenerated,
                       fieldConfiguration.Options.ColumnName,
                       fieldConfiguration.Options.DefaultValue,
                       fieldConfiguration.Options.IsPrimaryKey,
                       new FieldGraphPath <PropertyField>(path.ToArray(), field as PropertyField)));
        }
示例#10
0
            public BindingTransformation CreateTransformation <TSource, TTarget>(IModelFieldOf <TSource> sourceField, IModelFieldOf <TTarget> targetField)
            {
                var tryParseMethod = _tryParseMethod;

                var fromParameter = Expression.Parameter(typeof(TSource), "from");
                var toParameter   = Expression.Parameter(typeof(TTarget).MakeByRefType(), "to");

                Expression body;

                if (tryParseMethod.DeclaringType == typeof(Enum))
                {
                    body = Expression.Call(tryParseMethod, fromParameter, Expression.Constant(false), toParameter);
                }
                else
                {
                    body = Expression.Call(tryParseMethod, fromParameter, toParameter);
                }

                return(Expression.Lambda <BindingTransformation>(body, fromParameter, toParameter).Compile());
            }
 public BindingTransformation CreateTransformation <TSource, TTarget>(
     IModelFieldOf <TSource> sourceField,
     IModelFieldOf <TTarget> targetField)
 {
     return(Transform);
 }
示例#12
0
 public override IModelNode VisitField <T>(IModelFieldOf <T> field)
 {
     return(new ValueNode {
         Value = _reader.ReadField <T>(field as PropertyField)
     });
 }
示例#13
0
 public IModelNode VisitField <T>(IModelFieldOf <T> field)
 {
     return(new SqlFieldConfigurationWrapper(
                new SqlFieldConfiguration <T>()
                ));
 }
 public override IModelNode VisitField <T>(IModelFieldOf <T> field)
 {
     Result = _transformFactory.CreateTransformation(_source, field);
     return(base.VisitField(field));
 }
示例#15
0
 public virtual IModelNode VisitField <T>(IModelFieldOf <T> field)
 {
     return(field);
 }