コード例 #1
0
        public void SetAll(T entity)
        {
            var reader     = new ViewReader <T>(entity);
            var entityView = EntityModel.GetEntityView <T>();

            foreach (var intersectedFields in entityView.ClassToEntityIntersection.IntersectedFields)
            {
                if (!intersectedFields.RightField.IsEntityLocalField)
                {
                    continue;
                }
                if (intersectedFields.RightField.IsPrimaryKey && intersectedFields.RightField.IsSeverGenerated)
                {
                    continue;
                }

                if (reader.CheckPath(intersectedFields.LeftPath))
                {
                    var value = reader.Read <object>(intersectedFields.LeftPath);
                    Set(
                        QueryExpression.Column(intersectedFields.RightField.Column.Name),
                        value
                        );
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Compiles the view specified as a template
        /// </summary>
        /// <param name="templatePath">The templates file path</param>
        /// <returns>A function that will generate rendered content</returns>
        public Func <object, string> CompileView
        (
            string templatePath
        )
        {
            Validate.IsNotEmpty(templatePath);

            var view = ViewReader.Read
                       (
                templatePath
                       );

            return(Compile(view.Content));
        }
コード例 #3
0
        private ValueExpression GetValueExpression(EntityField <T> entityField, T entity)
        {
            var interesectedFields = _entityView.ClassToEntityIntersection
                                     .IntersectedFields.FirstOrDefault(q => q.RightField == entityField);

            if (interesectedFields == null)
            {
                ExceptionHelper.ThrowEntityFieldNotFound();
            }

            var reader = new ViewReader <T>(entity);
            var value  = reader.Read <object>(interesectedFields.LeftPath);

            return(ORMQueryExpressions.Value(value));
        }
コード例 #4
0
        public void Set(EntityField <T> schemaField, T entity)
        {
            var graphReader       = new ViewReader <T>(entity);
            var entityView        = EntityModel.GetEntityView <T>();
            var intersectedFields = entityView
                                    .ClassToEntityIntersection.IntersectedFields
                                    .FirstOrDefault(q => q.RightField == schemaField);

            if (intersectedFields == null)
            {
                ExceptionHelper.ThrowEntityFieldNotFound();
            }

            Set(
                QueryExpression.Column(intersectedFields.RightField.Column.Name),
                graphReader.Read <object>(intersectedFields.LeftPath)
                );
        }
コード例 #5
0
        public void Read_Converted_Object_Returns_Correct_Value()
        {
            var schema = new SchemaBuilder()
                         .Define <EntityModel>()
                         .AddTypeConverters(new[] { new SubConverter() })
                         .Build();
            var entityModel = schema.GetEntityModel <EntityModel>();
            var viewModel   = entityModel.GetEntityView <ViewModel>();
            var instance    = new ViewModel
            {
                Id  = 1,
                Sub = new SubViewModel
                {
                    OtherData = "Hello World"
                }
            };
            var reader   = new ViewReader <ViewModel>(instance);
            var readPath = viewModel.ClassToEntityIntersection
                           .IntersectedFields.First(q => q.LeftField.FieldName == "Data").LeftPath;
            var value = reader.Read <object>(readPath);

            Assert.AreEqual(instance.Sub.OtherData, value);
        }