private void GenerateEntities(ImportTablesEventArgs args, SampleOrmModel ormModel)
        {
            using (var transaction = ormModel.Store.TransactionManager.BeginTransaction())
            {
                foreach (var tableDefinition in args.TableDefinitions)
                {
                    var entityElement = new EntityElement(ormModel.Store, null)
                    {
                        Name      = tableDefinition.TableName,
                        TableName = tableDefinition.TableName
                    };

                    foreach (var columnDefinition in tableDefinition.ColumnDefinitions)
                    {
                        var property = new Property(ormModel.Store, null)
                        {
                            ColumnName = columnDefinition.ColumnName,
                            Name       = columnDefinition.ColumnName,
                            Type       = TypeCode.String
                        };

                        entityElement.Properties.Add(property);
                    }

                    ormModel.Elements.Add(entityElement);
                }

                transaction.Commit();
            }
        }
示例#2
0
		private static void WriteChildElements(DslModeling::SerializationContext serializationContext, EntityElement element, global::System.Xml.XmlWriter writer)
		{
			// EntityHasRelationShips
			global::System.Collections.ObjectModel.ReadOnlyCollection<EntityHasRelationShips> allEntityHasRelationShipsInstances = EntityHasRelationShips.GetLinksToEntityElements(element);
			if (!serializationContext.Result.Failed && allEntityHasRelationShipsInstances.Count > 0)
			{
				writer.WriteStartElement("entityElements");
				foreach (EntityHasRelationShips eachEntityHasRelationShipsInstance in allEntityHasRelationShipsInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					DslModeling::DomainClassXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(eachEntityHasRelationShipsInstance.GetDomainClass().Id);
					global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for " + eachEntityHasRelationShipsInstance.GetDomainClass().Name + "!");
					relSerializer.Write(serializationContext, eachEntityHasRelationShipsInstance, writer);
				}
				writer.WriteEndElement();
			}
	
			// EntityHasProperties
			global::System.Collections.ObjectModel.ReadOnlyCollection<EntityHasProperties> allEntityHasPropertiesInstances = EntityHasProperties.GetLinksToProperties(element);
			if (!serializationContext.Result.Failed && allEntityHasPropertiesInstances.Count > 0)
			{
				writer.WriteStartElement("properties");
				foreach (EntityHasProperties eachEntityHasPropertiesInstance in allEntityHasPropertiesInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					DslModeling::DomainClassXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(eachEntityHasPropertiesInstance.GetDomainClass().Id);
					global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for " + eachEntityHasPropertiesInstance.GetDomainClass().Name + "!");
					relSerializer.Write(serializationContext, eachEntityHasPropertiesInstance, writer);
				}
				writer.WriteEndElement();
			}
	
			// EntityHasReferences
			global::System.Collections.ObjectModel.ReadOnlyCollection<EntityHasReferences> allEntityHasReferencesInstances = EntityHasReferences.GetLinksToReferences(element);
			if (!serializationContext.Result.Failed && allEntityHasReferencesInstances.Count > 0)
			{
				writer.WriteStartElement("references");
				foreach (EntityHasReferences eachEntityHasReferencesInstance in allEntityHasReferencesInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					DslModeling::DomainClassXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(eachEntityHasReferencesInstance.GetDomainClass().Id);
					global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for " + eachEntityHasReferencesInstance.GetDomainClass().Name + "!");
					relSerializer.Write(serializationContext, eachEntityHasReferencesInstance, writer);
				}
				writer.WriteEndElement();
			}
	
		}
示例#3
0
		/// <summary>
		/// Reads all instances of relationship EntityHasReferences.
		/// </summary>
		/// <remarks>
		/// The caller will position the reader at the open tag of the first XML element inside the relationship tag, so it can be
		/// either the first instance, or a bogus tag. This method will deserialize all instances and ignore all bogus tags. When the
		/// method returns, the reader will be positioned at the end tag of the relationship (or EOF if somehow that happens).
		/// </remarks>
		/// <param name="serializationContext">Serialization context.</param>
		/// <param name="element">In-memory EntityElement instance that will get the deserialized data.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		private static void ReadEntityHasReferencesInstances(DslModeling::SerializationContext serializationContext, EntityElement element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newEntityHasReferencesSerializer = serializationContext.Directory.GetSerializer(EntityHasReferences.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newEntityHasReferencesSerializer != null, "Cannot find serializer for EntityHasReferences!");
				EntityHasReferences newEntityHasReferences = newEntityHasReferencesSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as EntityHasReferences;
				if (newEntityHasReferences != null)
				{
					DslModeling::DomainRoleInfo.SetRolePlayer (newEntityHasReferences, EntityHasReferences.EntityElementDomainRoleId, element);
					DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newEntityHasReferences.GetDomainClass().Id);	
					global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newEntityHasReferences.GetDomainClass().Name + "!");
					targetSerializer.Read(serializationContext, newEntityHasReferences, reader);
				}
				else
				{	// Maybe the relationship is serialized in short-form by mistake.
					DslModeling::DomainClassXmlSerializer newReferenceOfEntityHasReferencesSerializer = serializationContext.Directory.GetSerializer(Reference.DomainClassId);
					global::System.Diagnostics.Debug.Assert(newReferenceOfEntityHasReferencesSerializer != null, "Cannot find serializer for Reference!");
					Reference newReferenceOfEntityHasReferences = newReferenceOfEntityHasReferencesSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as Reference;
					if (newReferenceOfEntityHasReferences != null)
					{
						OrmLanguageSerializationBehaviorSerializationMessages.ExpectingFullFormRelationship(serializationContext, reader, typeof(EntityHasReferences));
						element.References.Add(newReferenceOfEntityHasReferences);
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newReferenceOfEntityHasReferences.GetDomainClass().Id);	
						global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newReferenceOfEntityHasReferences.GetDomainClass().Name + "!");
						targetSerializer.Read(serializationContext, newReferenceOfEntityHasReferences, reader);
					}
					else
					{	// Unknown element, skip.
						DslModeling::SerializationUtilities.Skip(reader);
					}
				}
			}
		}
示例#4
0
		private static void ReadEntityHasRelationShipsInstances(DslModeling::SerializationContext serializationContext, EntityElement element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newEntityHasRelationShipsSerializer = serializationContext.Directory.GetSerializer(EntityHasRelationShips.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newEntityHasRelationShipsSerializer != null, "Cannot find serializer for EntityHasRelationShips!");
				EntityHasRelationShips newEntityHasRelationShips = newEntityHasRelationShipsSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as EntityHasRelationShips;
				if (newEntityHasRelationShips != null)
				{
					DslModeling::DomainRoleInfo.SetRolePlayer (newEntityHasRelationShips, EntityHasRelationShips.SourceEntityElementDomainRoleId, element);
					DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newEntityHasRelationShips.GetDomainClass().Id);	
					global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newEntityHasRelationShips.GetDomainClass().Name + "!");
					targetSerializer.Read(serializationContext, newEntityHasRelationShips, reader);
				}
				else
				{	// Maybe the relationship is serialized in short-form by mistake.
					DslModeling::DomainClassXmlSerializer newEntityElementMonikerOfEntityHasRelationShipsSerializer = serializationContext.Directory.GetSerializer(EntityElement.DomainClassId);
					global::System.Diagnostics.Debug.Assert(newEntityElementMonikerOfEntityHasRelationShipsSerializer != null, "Cannot find serializer for EntityElement!");
					DslModeling::Moniker newEntityElementMonikerOfEntityHasRelationShips = newEntityElementMonikerOfEntityHasRelationShipsSerializer.TryCreateMonikerInstance(serializationContext, reader, element, EntityHasRelationShips.DomainClassId, element.Partition);
					if (newEntityElementMonikerOfEntityHasRelationShips != null)
					{
						OrmLanguageSerializationBehaviorSerializationMessages.ExpectingFullFormRelationship(serializationContext, reader, typeof(EntityHasRelationShips));
						new EntityHasRelationShips(element.Partition, new DslModeling::RoleAssignment(EntityHasRelationShips.SourceEntityElementDomainRoleId, element), new DslModeling::RoleAssignment(EntityHasRelationShips.TargetEntityElementDomainRoleId, newEntityElementMonikerOfEntityHasRelationShips));
						DslModeling::SerializationUtilities.Skip(reader);	// Moniker contains no child XML elements, so just skip.
					}
					else
					{	// Unknown element, skip.
						DslModeling::SerializationUtilities.Skip(reader);
					}
				}
			}
		}
示例#5
0
		/// <summary>
		/// This method deserializes all child model elements.
		/// </summary>
		/// <remarks>
		/// The caller will position the reader at the open tag of the first child XML element to deserialized.
		/// This method will read as many child elements as it can. It returns under three circumstances:
		/// 1) When an unknown child XML element is encountered. In this case, this method will position the reader at the 
		///    open tag of the unknown element. This implies that if the first child XML element is unknown, this method 
		///    should return immediately and do nothing.
		/// 2) When all child XML elemnets are read. In this case, the reader will be positioned at the end tag of the parent element.
		/// 3) EOF.
		/// </remarks>
		/// <param name="serializationContext">Serialization context.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		/// <param name="element">In-memory EntityElement instance that will get the deserialized data.</param>
		private static void ReadChildElements(DslModeling::SerializationContext serializationContext, EntityElement element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				switch (reader.LocalName)
				{
					case "entityElements":	// Relationship "EntityHasRelationShips"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <entityElements>
							ReadEntityHasRelationShipsInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </entityElements>
						}
						break;
					case "properties":	// Relationship "EntityHasProperties"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <properties>
							ReadEntityHasPropertiesInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </properties>
						}
						break;
					case "references":	// Relationship "EntityHasReferences"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <references>
							ReadEntityHasReferencesInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </references>
						}
						break;
					default:
						return;  // Don't know this element.
				}
			}
		}
        private void GenerateEntities(ImportTablesEventArgs args, SampleOrmModel ormModel)
        {
            using (var transaction = ormModel.Store.TransactionManager.BeginTransaction())
            {
                foreach (var tableDefinition in args.TableDefinitions)
                {
                    var entityElement = new EntityElement(ormModel.Store, null)
                    {
                        Name = tableDefinition.TableName,
                        TableName = tableDefinition.TableName
                    };

                    foreach (var columnDefinition in tableDefinition.ColumnDefinitions)
                    {
                        var property = new Property(ormModel.Store, null)
                        {
                            ColumnName = columnDefinition.ColumnName,
                            Name = columnDefinition.ColumnName,
                            Type = TypeCode.String
                        };

                        entityElement.Properties.Add(property);
                    }

                    ormModel.Elements.Add(entityElement);
                }

                transaction.Commit();
            }
        }