protected override void UpdateEdmx(TEdmx edmx) { var scalarProperties = from esm in edmx.Runtime.Mappings.Mapping.EntityContainerMapping.EntitySetMapping from etm in esm.EntityTypeMapping from f in etm.MappingFragment from sp in f.ScalarProperty select new { ScalarProperty = sp, etm.TypeName }; var mapQuery = from sp in scalarProperties let item = new { sp.TypeName, sp.ScalarProperty.Name, sp.ScalarProperty.ColumnName } group item by sp.TypeName into g select g; //build map of new entity property names var map = mapQuery.ToDictionary(g => g.Key, g => g.Distinct().ToDictionary(sp => sp.Name, sp => UpdateName(sp.ColumnName))); //update map property names: foreach (var sp in scalarProperties) { sp.ScalarProperty.Name = map[sp.TypeName][sp.ScalarProperty.Name]; } //conceptual entities foreach (var entity in edmx.Runtime.ConceptualModels.Schema.EntityType) { var typeName = String.Format("{0}.{1}", edmx.Runtime.ConceptualModels.Schema.Namespace, entity.Name); var typeMap = map[typeName]; //keys foreach (var keyRef in entity.Key.PropertyRef) { keyRef.Name = typeMap[keyRef.Name]; } //conceptual properties foreach (var property in entity.Property) { property.Name = typeMap[property.Name]; } } var principalPropertyQuery = from association in edmx.Runtime.ConceptualModels.Schema.Association let end = association.End.Where(e => e.Role == association.ReferentialConstraint.Principal.Role).Single() from property in association.ReferentialConstraint.Principal.PropertyRef select new { TypeName = end.Type, Property = property }; var dependentPropertyQuery = from association in edmx.Runtime.ConceptualModels.Schema.Association let end = association.End.Where(e => e.Role == association.ReferentialConstraint.Dependent.Role).Single() from property in association.ReferentialConstraint.Dependent.PropertyRef select new { TypeName = end.Type, Property = property }; foreach (var property in principalPropertyQuery.Union(dependentPropertyQuery)) { property.Property.Name = map[property.TypeName][property.Property.Name]; } }
/// <summary> /// Builds an empty <see cref="Edmx"/> instance in which to load metadata content. /// </summary> /// <returns></returns> private static Edmx BuildEmptyEdmx() { var runtime = new Runtime { ConceptualModels = new ConceptualModels(), StorageModels = new StorageModels(), Mappings = new Mappings() }; var tedmx = new TEdmx { Runtimes = new List <Runtime> { runtime } }; return(new Edmx(tedmx)); }
protected abstract void UpdateEdmx(TEdmx edmx);
private void SetInnerType(TEdmx contentField) { Content = ((TEdmx)(XTypedServices.GetCloneIfRooted(contentField))); XTypedServices.SetName(this, Content); }
/// <summary> /// Initializes a new instance of the <see cref="Edmx"/> class. /// </summary> /// <param name="content">The content.</param> public Edmx(TEdmx content) { SetInnerType(content); }