Ejemplo n.º 1
0
		private void GenerateSelectFromClause(StringBuilder text, FromClause from)
		{
			if(from == null)
				return;

			var mapping = MetadataManager.Default.GetMapping(from.Entity.QualifiedName) as MetadataMappingEntity;
			var tableName = mapping.StorageEntity.GetAttributeValue("name");

			text.AppendFormat("FROM {0} AS {1}", tableName, from.Alias);
			text.AppendLine();

			foreach(var join in from.Joins)
			{
				text.AppendFormat(@"\tLEFT JOIN {0} AS {1} ON", join.Entity, join.Alias);
				text.AppendLine();

				for(int i = 0; i < join.DependentRefs.Count; i++)
				{
					text.AppendFormat("", join.Alias, join.DependentRefs[i].Name, join.Refs[i].Name);
				}
			}
		}
Ejemplo n.º 2
0
		internal FromClause GetSelectFromClause(string qualifiedName, string scope)
		{
			if(string.IsNullOrWhiteSpace(qualifiedName))
				throw new ArgumentNullException("qualifiedName");

			var entity = MetadataManager.Default.GetConceptElement<MetadataEntity>(qualifiedName);

			if(entity == null)
				throw new DataException(string.Format("Not found the concept entity with '{0}'.", qualifiedName));

			var index = 1;
			var inherits = DataUtility.GetInherits(entity);
			var from = new FromClause(inherits.Pop(), index++);

			while(inherits.Count > 0)
			{
				var current = inherits.Pop();
				from.Joins.Add(new JoinClauseEx(index++, current, current.Key, from.Entity.Key));
			}

			var members = DataUtility.ResolveScope(entity, scope);

			foreach(var member in members)
			{
				var parts = member.Split('.');

				for(int i = 0; i < parts.Length; i++)
				{
					var property = entity.GetProperty(parts[i]) as MetadataEntityComplexProperty;

					if(property != null && (property.Relationship.IsOneToOne() || property.Relationship.IsManyToOne()))
					{
						var memberName = string.Join(".", parts, 0, i);
						var join = this.FindJoinClause(from.Joins, jc => jc.NavigationPropertyName == memberName);

						if(join == null)
						{
							join = new JoinClauseEx(index++,
								property.Relationship.GetToEntity(),
								property.Relationship.GetToEntityReferences().ToArray(),
								property.Relationship.GetFromEntityReferences().ToArray())
							{
								NavigationPropertyName = memberName,
							};

							if(from.Entity == property.Relationship.GetFromEntity())
							{
								from.Joins.Add(join);
							}
							else
							{
								var parent = this.FindJoinClause(from.Joins, jc => jc.Entity == property.Relationship.GetFromEntity());

								if(parent == null)
									parent.Children.Add(join);
							}
						}
					}
				}
			}

			return from;
		}