private static IEnumerable<IExpressionPiece> BreakExpression(IEntityTranslator translator, LambdaExpression expression) { var current = GetFirstMember(expression); while (current != null) { var part = new ExpressionPiece { PropertyName = current.Member.Name, EntityType = current.Member.DeclaringType }; // Gets the table for this entity type. part.EntityTable = translator.Translate(part.EntityType); // Gets the field used in this expression part. part.Field = part.EntityTable .Fields .FirstOrDefault(f => f.Info.Name == part.PropertyName); Debug.Assert(part.Field != null, "The property [" + part.PropertyName + "] used in the expression doesn't belong to the Entity table representation."); yield return part; current = current.Expression as MemberExpression; } }
public static Task <TranslateResult <TSchema> > Translate <TInput, TSchema>(this IEntityTranslator <TInput, TSchema> translator, EntityResult <TSchema> result, Result <Cursor <TSchema>, TInput> input) where TSchema : Entity where TInput : TSchema { var context = new EntityTranslateContext <TInput, TSchema>(result, input); return(translator.Translate(context)); }
public async Task <Entity <TEntity> > GetProperty(TranslateContext <TInput, TSchema> context) { var entity = await _provider.GetProperty(context).ConfigureAwait(false); var entityContext = context.CreateContext(entity.Value); var result = await _translator.Translate(entityContext).ConfigureAwait(false); if (result.TryGetEntity <TEntity>(0, out var entityResult)) { return(new EntityProperty <TEntity>(entityResult)); } return(new EntityProperty <TEntity>()); }
public async Task Apply(TResult entity, TranslateContext <TInput, TSchema> context) { var inputValue = _inputProperty.Get(context.Input) ?? Value.Missing <TEntity>(); TranslateContext <TEntity, TSchema> inputContext = context.CreateContext(inputValue.Value); var result = await _entityTranslator.Translate(inputContext).ConfigureAwait(false); if (result.HasResult && result.TryGetEntity(0, out TEntity resultEntity)) { _property.Set(entity, new ConstantValue <TEntity>(resultEntity)); } else { _property.Set(entity, Value.Missing <TEntity>()); } }
public TTarget Translate <TTarget>(object source, object param) { Type targetType = typeof(TTarget); Type sourceType = source.GetType(); if (targetType == null) { throw new ArgumentNullException("targetType"); } if (sourceType == null) { throw new ArgumentNullException("sourceType"); } if (source == null) { if (targetType.IsArray) { return(default(TTarget)); } else { throw new ArgumentNullException("source"); } } if (IsArrayConversionPossible(targetType, sourceType)) { return((TTarget)TranslateArray(targetType, source)); } else { IEntityTranslator translator = FindTranslator(targetType, sourceType); if (translator == null) { translator = FindTranslator(targetType, sourceType.BaseType); } if (translator != null) { return((TTarget)translator.Translate(this, targetType, source, param)); } } throw new EntityTranslatorException(string.Format("No translator is available to map from {0} to {1}.", sourceType.GetTypeString(), targetType.GetTypeString())); }
public object Translate(Type targetType, object source) { if (targetType == null) { throw new ArgumentNullException("targetType"); } if (source == null) { if (targetType.IsArray) { return(null); } else { throw new ArgumentNullException("source"); } } Type sourceType = source.GetType(); ///----- Added By Ericsson ///---temoprary solution for fixing the dynamic proxy if (sourceType.BaseType != null && sourceType.Namespace == "System.Data.Entity.DynamicProxies") { sourceType = sourceType.BaseType; } if (IsArrayConversionPossible(targetType, sourceType)) { return(TranslateArray(targetType, source)); } else { IEntityTranslator translator = FindTranslator(targetType, sourceType); if (translator != null) { return(translator.Translate(this, targetType, source)); } } throw new EntityTranslatorException("No translator is available to perform the operation."); }
private void Exchange(IEntityAdapter adapter, IEntityTranslator translator) { using (IComWrapper cursor = adapter.GetCursor()) { if (cursor != null) { while ((bool)cursor.Call("Следующий")) { using (SqlCommand command = connection.CreateCommand()) { translator.Translate(cursor, command); AddParameter(command, "id_sea", SqlDbType.Int, ParameterDirection.Input, session_id); command.ExecuteNonQuery(); } } } } log.Write(string.Format("ok : {0}", adapter.ToString())); }
public object Translate(Type targetType, Type sourceType, object source) { if (targetType == null) { throw new ArgumentNullException("targetType"); } if (sourceType == null) { throw new ArgumentNullException("sourceType"); } if (source == null) { if (targetType.IsArray) { return(null); } else { throw new ArgumentNullException("source"); } } if (IsArrayConversionPossible(targetType, sourceType)) { return(TranslateArray(targetType, source)); } else { IEntityTranslator translator = FindTranslator(targetType, sourceType); if (translator == null) { translator = FindTranslator(targetType, sourceType.BaseType); } if (translator != null) { return(translator.Translate(this, targetType, source)); } } throw new EntityTranslatorException(string.Format("No translator is available to map from {0} to {1}.", sourceType.GetTypeString(), targetType.GetTypeString())); }
public object Translate(Type targetType, object source) { if (targetType == null) { throw new ArgumentNullException("targetType"); } if (source == null) { if (targetType.IsArray) { return(null); } else { throw new ArgumentNullException("source"); } } Type sourceType = source.GetType(); if (IsArrayConversionPossible(targetType, sourceType)) { return(TranslateArray(targetType, source)); } else { IEntityTranslator translator = FindTranslator(targetType, sourceType); if (translator != null) { return(translator.Translate(this, targetType, source)); } } throw new EntityTranslatorException("No translator is available to perform the operation."); }
private static IField SetFieldBindMember(IEntityTranslator translator, PropertyInfo item, Field field) { var bind = item.Attribute<DbBindAttribute>(); String bindFieldName = null; MethodInfo getMethod = item.GetGetMethod(); if (bind != null) { if (!getMethod.IsVirtual) { throw new InvalidMappingException("The field [{0}] is marked with DbBind but is not Virtual.", field.Name); } bindFieldName = bind.FieldName; } if (getMethod.IsVirtual && !getMethod.ReturnType.Assembly.FullName.StartsWith("mscorlib, ")) { bindFieldName = bindFieldName ?? field.Name; var table = item.PropertyType != field.EntityType ? translator.Translate(item.PropertyType) : field.Table; field.BindToField = table.Fields .FirstOrDefault(f => f.Name.Equals(bindFieldName, StringComparison.InvariantCultureIgnoreCase)); if (field.BindToField == null) { throw new InvalidMappingException("The field [{0}] is a reference to the table [{1}] but no match was found.", field.Name, table.Name); } return new BindedField(field); } return field; }
public static IEnumerable<ITable> ToTables(this IEnumerable<Type> type, IEntityTranslator translator) { return TestModels .Select(t => translator.Translate(t)); }
// GET: Empresa public async Task <IActionResult> Index() { var empresas = await _empresaManager.ListAllAsync(); return(View(_translator.Translate <List <EmpresaViewModel> >(empresas.ToList()))); }