Exemplo n.º 1
0
        public static HashSet <TableSchema.Relation> FindRelations(LambdaExpression expression, TableSchema schema)
        {
            var finder = new LambdaRelationFinder(schema);

            finder.Visit(expression.Body);

            return(finder._relations);
        }
Exemplo n.º 2
0
        private Task _LoadRelationsAsync(object obj, IEnumerable <LambdaExpression> relationsToLoad)
        {
            return(Task.Run(() =>
            {
                TableSchema parentSchema = GetSchema(obj.GetType());

                Ir.LoadRelations(obj, LambdaRelationFinder.FindRelations(relationsToLoad, parentSchema));
            }));
        }
Exemplo n.º 3
0
        internal T Load(T obj, object key, params Expression <Func <T, object> >[] relationsToLoad)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            Dictionary <string, object> primaryKey;

            var keyTypeInspector = key.GetType().Inspector();

            if (keyTypeInspector.Is(TypeFlags.Numeric | TypeFlags.Enum | TypeFlags.String))
            {
                if (Schema.PrimaryKeys.Length != 1)
                {
                    throw new Exception($"Invalid key for {typeof (T)}");
                }

                primaryKey = new Dictionary <string, object>()
                {
                    { Schema.PrimaryKeys[0].MappedName, key }
                };
            }
            else
            {
                primaryKey = Schema.PrimaryKeys.ToDictionary(pk => pk.MappedName, pk => GetFieldOrPropertyValue(key, pk.FieldName));
            }

            var serializedEntity = DataProvider.ReadObject(primaryKey, Schema);

            if (serializedEntity == null)
            {
                return(default(T));
            }

            Schema.UpdateObject(obj, serializedEntity);

            var relations = LambdaRelationFinder.FindRelations(relationsToLoad, Schema);

            if (Schema.DatasetRelations != null)
            {
                if (relations == null)
                {
                    relations = new HashSet <TableSchema.Relation>(Schema.DatasetRelations);
                }
                else
                {
                    relations.UnionWith(Schema.DatasetRelations);
                }
            }

            return(Ir.WithLoadedRelations(obj, relations));
        }
Exemplo n.º 4
0
 public override HashSet <TableSchema.Relation> FindRelations(TableSchema schema)
 {
     return(LambdaRelationFinder.FindRelations(Expression, schema));
 }
Exemplo n.º 5
0
        private void _LoadRelations(object obj, IEnumerable <LambdaExpression> relationsToLoad /*, TableSchema parentSchema*/)
        {
            TableSchema parentSchema = GetSchema(obj.GetType());

            Ir.LoadRelations(obj, LambdaRelationFinder.FindRelations(relationsToLoad, parentSchema));
        }