Exemplo n.º 1
0
        public Link(string entityName, string toEntityName, string fromAttributeName, string toAttributeName, JoinOperator joinOperator, bool addColumns) : base(entityName)
        {
            ToEntityName      = toEntityName;
            FromAttributeName = fromAttributeName;
            ToAttributeName   = toAttributeName;
            JoinOperator      = joinOperator;
            DoAddColumns      = addColumns;
            Criteria          = new QueryCriteria(LogicalOperator.And, ToEntityName);

            if (addColumns)
            {
                try
                {
                    TargetDefinition = DefinitionCache.GetEntityDefinition(toEntityName);

                    if (!string.IsNullOrEmpty(TargetDefinition.PrimaryIdAttributeName))
                    {
                        AddColumn(TargetDefinition.PrimaryIdAttributeName);
                    }

                    if (!string.IsNullOrEmpty(TargetDefinition.PrimaryNameAttributeName))
                    {
                        AddColumn(TargetDefinition.PrimaryNameAttributeName);
                    }
                }
                catch (KeyNotFoundException)
                {
                    // définition non trouvée
                }
            }
        }
Exemplo n.º 2
0
        public override string ToWebApiString(Func <int> aliasIndexer = null)
        {
            var definition       = DefinitionCache.GetEntityDefinition(EntityName);
            var targetDefinition = DefinitionCache.GetEntityDefinition(ToEntityName);
            var sb = new StringBuilder();

            var relationship = definition.GetRelationshipByAttributeNameAndTargetEntityName(FromAttributeName, ToEntityName);

            if (relationship == null)
            {
                return(string.Empty);
            }

            sb.Append(relationship.NavigationPropertyName);

            if (Attributes.Any())
            {
                sb.Append("($select=");
                foreach (var attribute in Attributes)
                {
                    sb.Append(attribute).Append(",");
                }

                sb.Remove(sb.Length - 1, 1);
                sb.Append(")");
            }

            return(sb.ToString());
        }
Exemplo n.º 3
0
        public Query(string entityName) : base(entityName)
        {
            Criteria = new QueryCriteria(LogicalOperator.And, EntityName);
            var definition = DefinitionCache.GetEntityDefinition(entityName);

            AddColumns(definition.PrimaryIdAttributeName, definition.PrimaryNameAttributeName);
        }
Exemplo n.º 4
0
 internal Condition(string entityName, string entityAlias, string attributeName, ConditionOperator conditionOperator)
 {
     EntityName          = entityName;
     AttributeName       = attributeName;
     Operator            = conditionOperator;
     EntityAlias         = entityAlias;
     Definition          = DefinitionCache.GetEntityDefinition(EntityName);
     AttributeType       = Definition?.GetAttributeType(AttributeName) ?? AttributeTypeCode.String;
     WebApiAttributeName = Definition?.GetWebApiAttributeName(AttributeName);
 }
Exemplo n.º 5
0
        public override string ToWebApiString(Func <int> aliasIndexer = null)
        {
            var definition = DefinitionCache.GetEntityDefinition(EntityName);

            if (!string.IsNullOrEmpty(PagingInfo.PagingCookie))
            {
                return(PagingInfo.PagingCookie.Substring(definition.EntityCollectionName.Length + 1));
            }

            var sb = new StringBuilder();

            sb.Append("$select=");
            foreach (var attribute in Attributes)
            {
                sb.Append(definition.GetWebApiAttributeName(attribute)).Append(",");
            }
            sb.Remove(sb.Length - 1, 1);

            if (Links.Any(l => l.Attributes.Any()))
            {
                sb.Append("&$expand=");
                foreach (var link in Links.Where(l => l.Attributes.Any()))
                {
                    sb.Append(link.ToWebApiString(() => _indexValue++)).Append(",");
                }

                sb.Remove(sb.Length - 1, 1);
            }

            if (Criteria.Conditions.Any() || Criteria.Filters.Any())
            {
                sb.Append("&$filter=");
                sb.Append(Criteria.ToWebApiString(() => _indexValue++));
            }

            if (_orders.Any())
            {
                sb.Append("&$orderby=");
                foreach (var order in _orders)
                {
                    sb.Append($"{definition.GetWebApiAttributeName(order.Item1)} ").Append(order.Item2 ? "desc," : "asc,");
                }

                sb.Remove(sb.Length - 1, 1);
            }

            if (TopCount.HasValue)
            {
                sb.Append($"&$top={TopCount}");
            }

            sb.Append(Criteria.WebApiAliasString);

            return(sb.ToString());
        }
Exemplo n.º 6
0
        private void InitializeMetadata()
        {
            var metadataList = new List <EntityMetadata>();

            foreach (var type in typeof(AccountDefinition).Assembly.GetExportedTypes())
            {
                if (type.GetCustomAttribute <EntityDefinitionAttribute>() == null)
                {
                    continue;
                }

                var definition = DefinitionCache.GetEntityDefinition(type);

                var metadata = definition.ToEntityMetadata();

                metadataList.Add(metadata);
            }
            //FakedContext.InitializeMetadata(metadataList);
        }