internal static Dictionary <string, IEnumerable <string> > GetRequiredNavProperties(string edmx) { var metadata = JObject.Parse(edmx)["schema"]; var relationships = new Dictionary <string, NavigationProperty>(); foreach (var node in metadata["entityType"]) { var typeName = (string)node["name"]; var navProp = node["navigationProperty"]; if (navProp == null) { continue; } IEnumerable <JToken> navPropEnumerator = navProp as JArray ?? (IEnumerable <JToken>) new[] { navProp }; foreach (var nav in navPropEnumerator) { string relationship = ((string)nav["relationship"]).ExtractAfterLastDot(); //remove self. var ep = new EdmxProperty { TypeName = typeName, PropertyName = (string)nav["name"] }; NavigationProperty n; if (relationships.TryGetValue(relationship, out n)) { n.AddProperty(ep); } else { relationships.Add(relationship, new NavigationProperty(ep)); } } } //uncomment the line below to find all entity relations which are 1 way (i.e. you have forgotten to map between both entities) Debug.WriteLine(string.Join("\r\n", from r in relationships let p = r.Value.UnmatchedProperty where p != null select string.Format("{0}: {1}.{2}", r.Key, p.TypeName, p.PropertyName))); foreach (var node in metadata["association"]) { var single = node["end"].FirstOrDefault(n => (string)n["multiplicity"] == "1"); var name = (string)node["name"]; //NOT dealing with 1..1 relationships as this is an edge case with the current DB if (single == null) { relationships.Remove(name); } else { relationships[name].SetSingleMultiplicityType(((string)single["type"]).ExtractAfterLastDot()); } } return(relationships.Values.Select(v => v.RequiredProperty) .ToLookup(k => k.TypeName, v => v.PropertyName.PascalToCamelCase()) .ToDictionary(k => k.Key, v => v.AsEnumerable())); //could return the lookup directly, but newtonsoft serialisation would require a custom converter }
internal static Dictionary<string,IEnumerable<string>> GetRequiredNavProperties(string edmx) { var metadata = JObject.Parse(edmx)["schema"]; var relationships = new Dictionary<string, NavigationProperty>(); foreach (var node in metadata["entityType"]) { var typeName = (string)node["name"]; var navProp = node["navigationProperty"]; if (navProp == null) { continue; } IEnumerable<JToken> navPropEnumerator = navProp as JArray ?? (IEnumerable<JToken>)new[] { navProp }; foreach (var nav in navPropEnumerator) { string relationship = ((string)nav["relationship"]).ExtractAfterLastDot(); //remove self. var ep = new EdmxProperty { TypeName = typeName, PropertyName = (string)nav["name"] }; NavigationProperty n; if (relationships.TryGetValue(relationship, out n)) { n.AddProperty(ep); } else { relationships.Add(relationship, new NavigationProperty(ep)); } } } //uncomment the line below to find all entity relations which are 1 way (i.e. you have forgotten to map between both entities) Debug.WriteLine(string.Join("\r\n", from r in relationships let p = r.Value.UnmatchedProperty where p != null select string.Format("{0}: {1}.{2}", r.Key, p.TypeName, p.PropertyName))); foreach (var node in metadata["association"]) { var single = node["end"].FirstOrDefault(n => (string)n["multiplicity"] == "1"); var name = (string)node["name"]; //NOT dealing with 1..1 relationships as this is an edge case with the current DB if (single==null) { relationships.Remove(name); } else { relationships[name].SetSingleMultiplicityType(((string)single["type"]).ExtractAfterLastDot()); } } return relationships.Values.Select(v => v.RequiredProperty) .ToLookup(k => k.TypeName, v => v.PropertyName.PascalToCamelCase()) .ToDictionary(k=>k.Key, v=>v.AsEnumerable()); //could return the lookup directly, but newtonsoft serialisation would require a custom converter }
public void AddProperty(EdmxProperty propName) { Debug.Assert(_properties[1] == null); _properties[1] = propName; }
public NavigationProperty(EdmxProperty propName) { _properties = new EdmxProperty[2]; _properties[0] = propName; }
public NavigationProperty(EdmxProperty propName) { _properties = new EdmxProperty[2]; _properties[0] = propName; }
public void AddProperty(EdmxProperty propName) { Debug.Assert(_properties[1] == null); _properties[1] = propName; }