// <EntitySet Name="Genres" EntityType="Movies.Genre" /> // <EntitySet Name="Movies" EntityType="Movies.Movie" /> // <EntitySet Name="People" EntityType="Movies.Person" /> // <EntitySet Name="Roles" EntityType="Movies.Role" /> public static MetaEntitySet Parse(MetaModel mmodel, MetaContainer c, XElement node) { if (node.Name.LocalName != NodeName) throw new Exception("Invalid Node. To parse an " + NodeName + " you need to provide an XElement with the same node name."); var fullName = c.FullName + '.' + node.Att("Name"); if (mmodel.EntitySets.ContainsKey(fullName)) return mmodel.EntitySets[fullName]; var m = new MetaEntitySet { FullName = fullName, Name = node.Att("Name"), Container = c }; mmodel.EntitySets.Add(fullName, m); m.EntityType = MetaEntityType.Parse(mmodel, node.Att("EntityType"), m); /* todo: process store // check for mapping var mapEnt = file.Mapping.d("EntitySetMapping").WithName(m.Name); if (mapEnt != null) { // we have a mapping! so we should have a MappingFrag... var mapFrag = mapEnt.d("MappingFragment").FirstOrDefault(); if (mapFrag != null) // load the store m.Store = MetaEntitySetStore.Parse(file, mapFrag.Att("StoreEntitySet")); } if (m.Store != null) { m.Store.EntityTypeStore = m.EntityType.Store; } */ return m; }
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; }