Ejemplo n.º 1
0
        /*
         * <Association Name="FK_movies_genres">
          <End Type="Movies.Genre" Role="genre" Multiplicity="0..1" />
          <End Type="Movies.Movie" Role="movie" Multiplicity="*" />
          <ReferentialConstraint>
        <Principal Role="genre">
          <PropertyRef Name="Id" />
        </Principal>
        <Dependent Role="movie">
          <PropertyRef Name="GenreId" />
        </Dependent>
          </ReferentialConstraint>
        </Association>
         * */
        public static MetaAssociationRole Parse(MetaModel mmodel, MetaEntityType fromET, XElement navP)
        {
            var fullName = navP.Att("Relationship") + '.' + navP.Att("ToRole");

            if(mmodel.AssociationRoles.ContainsKey(fullName))
                return mmodel.AssociationRoles[fullName];

            // navP : <NavigationProperty Name="Movies" Relationship="Movies.FK_movies_genres" FromRole="genre" ToRole="movie" />
            var a = new MetaAssociationRole();

            a.FullName = fullName;
            a.Name = a.FullName.LastPart();
            a.NavigationProperty = (from p in fromET.NavigationProperties where p.Name == navP.Att("Name") select p).FirstOrDefault();

            mmodel.AssociationRoles.Add(a.FullName, a);

            var assNode = mmodel.EdmxFile.Concept.D("Association").WithName(navP.Att("Relationship").LastPart());

            var role = assNode.Es("End").FirstWhere("Role", navP.Att("ToRole"));

            var toE = mmodel.EntityTypes.ContainsKey(role.Att("Type")) ? mmodel.EntityTypes[role.Att("Type")] : MetaEntityType.Parse(mmodel, role.Att("Type"));

            a.MultiplicityValue = role.Att("Multiplicity");
            a.ToEntityType = toE;

            return a;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <example>
        /// Xml example:
        /// <![CDATA[
        ///		<Property Name="Shooting" Type="Movies.Location" Nullable="false" />
        /// ]]>
        /// </example>
        ///<param name="mmodel"></param>
        ///<param name="entityType"> </param>
        ///<param name="scP"></param>
        ///<returns></returns>
        public static MetaComplexProperty Parse(MetaModel mmodel, MetaEntityType entityType, XElement scP)
        {
            var p = new MetaComplexProperty
                        {
                            EntityType = entityType,
                            FullName = entityType.FullName.Dot(scP.Att("Name")),
                            Name = scP.Att("Name"),
                            Nullable = scP.Att("Name").ToLower() == "true"
                        };

            mmodel.ComplexProperties.Add(p.FullName, p);

            MetaComplexType ct;

            if (mmodel.ComplexTypes.ContainsKey(scP.Att("Type")))
                ct = mmodel.ComplexTypes[scP.Att("Type")];
            else
            {
                var ctNode = MetaComplexType.FindNode(mmodel, scP.Att("Type"));

                if(ctNode == null)
                    throw new Exception("Couldn't find the ComplexType " + scP.Att("Type") +
                        ". The type was used in " + entityType.FullName.Dot(scP.Att("Name")));

                ct = MetaComplexType.Parse(mmodel, ctNode);
            }

            p.ComplexType = ct;

            return p;
        }
Ejemplo n.º 3
0
        public static MetaScalarProperty Parse(MetaModel mmodel, MetaEntityType et, XElement node)
        {
            var fullName = et.FullName + '.' + node.Att("Name");

            if (mmodel.ScalarProperties.ContainsKey(fullName))
                return mmodel.ScalarProperties[fullName];

            var sp = new MetaScalarProperty()
                   	{
                   		FullName = fullName,
                   		Name = node.Att("Name"),
                   		Nullable = node.Att("Nullable") == "true",
                   		Type = node.Att("Type"),
                   		EntityType = et
                   	};

            mmodel.ScalarProperties.Add(fullName, sp);

            return sp;
        }
Ejemplo n.º 4
0
        // <NavigationProperty Name="Movies" Relationship="Movies.FK_movies_genres" FromRole="genre" ToRole="movie" />
        public static MetaNavigationProperty Parse(MetaModel mmodel, MetaEntityType et, XElement node)
        {
            var fullName = et.FullName + '.' + node.Att("Name");

            if (mmodel.NavigationProperties.ContainsKey(fullName))
                return mmodel.NavigationProperties[fullName];

            var m = new MetaNavigationProperty
                        {
                            FullName = fullName,
                            Name = node.Att("Name")
                        };

            mmodel.NavigationProperties.Add(fullName, m);

            m.AssociationRole = MetaAssociationRole.Parse(mmodel, et, node);

            m.EntityType = m.AssociationRole.ToEntityType;

            return m;
        }
Ejemplo n.º 5
0
        /// <summary>
        ///	Links a MetaEntityType with a MetaEntityTypeStore all the way down do the properties.
        /// </summary>
        /// <example>
        ///		Mapping Xml:
        ///		<![CDATA[
        ///    <EntityTypeMapping TypeName="Movies.Movie">
        ///      <MappingFragment StoreEntitySet="movies">
        ///        <ScalarProperty Name="GenreId" ColumnName="genre_id" />
        ///        <ScalarProperty Name="Published" ColumnName="published" />
        ///        <ScalarProperty Name="Synopsis" ColumnName="synopsis" />
        ///        <ScalarProperty Name="Name" ColumnName="name" />
        ///        <ScalarProperty Name="Id" ColumnName="movie_id" />
        ///        <ComplexProperty Name="Shooting">
        ///          <ScalarProperty Name="Country" ColumnName="shooting_country" />
        ///          <ScalarProperty Name="State" ColumnName="shooting_state" />
        ///          <ScalarProperty Name="City" ColumnName="shooting_city" />
        ///        </ComplexProperty>
        ///      </MappingFragment>
        ///    </EntityTypeMapping>
        ///		]]>
        /// </example>
        public static void Link(MetaEntityType et, MetaEntityTypeStore ets, XElement mapping)
        {
            /*
            var propDic = (from prop in et.Properties select prop).ToDictionary(k => k.Name);
            var stPropDic = (from prop in ets.PropertiesStores select prop).ToDictionary(k => k.Name);

            foreach (var scP in mapping.d("ScalarProperty"))
            {
                MetaScalarProperty.Link(propDic[scP.Att("Name")], stPropDic[scP.Att("ColumnName")]);
            }

            var cPropDic = (from prop in et.ComplexProperties select prop).ToDictionary(k => k.Name);
            var stCPropDic = (from prop in ets.PropertyStores select prop).ToDictionary(k => k.Name);

            foreach (var scP in mapping.d("ComplexProperty"))
            {
                MetaComplexProperty.
                MetaScalarProperty.Link(propDic[scP.Att("Name")], stPropDic[scP.Att("ColumnName")]);
            }
             * */
        }
Ejemplo n.º 6
0
        public static MetaEntityType Parse(MetaModel mmodel, string fullName, MetaEntitySet eSet = null)
        {
            if (mmodel.EntityTypes.ContainsKey(fullName))
                return mmodel.EntityTypes[fullName];

            var m = new MetaEntityType
                        {
                            FullName = fullName,
                            Name = fullName.LastPart(),
                            EntitySet = eSet
                        };

            // need to add before processing related meta-models
            mmodel.EntityTypes.Add(m.FullName, m);

            var node = mmodel.EdmxFile.Concept.D(NodeName).WithName(m.Name);

            var keyNames = (from k in node.D("PropertyRef") select k.Att("Name")).ToList();

            // parsing properties
            foreach (var scP in node.D("Property"))
            {
                // Property elements with a Type attribute reprents a ComplexProperty
                if (MetaComplexProperty.IsComplexPropertyNode(mmodel, scP))
                {
                    m.ComplexProperties.Add(MetaComplexProperty.Parse(mmodel, m, scP));
                }
                else
                {
                    var sp = MetaScalarProperty.Parse(mmodel, m, scP);
                    sp.isKey = keyNames.Contains(scP.Att("Name"));

                    m.Properties.Add(sp);
                }
            }

            foreach (var navP in node.D("NavigationProperty"))
            {
                m.NavigationProperties.Add(MetaNavigationProperty.Parse(mmodel, m, navP));
            }

            // todo: process store

            return m;
        }