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 ); } } }
/// <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)); }
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)); }
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) ); }
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); }