Skip to content

Instantly share code, notes, and snippets.

@szunyog
Created June 17, 2014 09:55
Show Gist options
  • Save szunyog/68916c088167197d960a to your computer and use it in GitHub Desktop.
Save szunyog/68916c088167197d960a to your computer and use it in GitHub Desktop.
Creates a list of the navigation and the belonging scalar properties.
private class Key
{
public string TypeName { get; set; }
public string NavPropertyName { get; set; }
public override string ToString()
{
return string.Format("{0}.{1}", TypeName, NavPropertyName);
}
}
private class Value
{
public string ScalarPropertyName { get; set; }
public string EndMemberType { get; set; }
public override string ToString()
{
return string.Format("{0} ({1})", ScalarPropertyName, EndMemberType);
}
}
private Dictionary<Key, Value> GetDependentProperties()
{
var result = new Dictionary<Key, Value>();
using (var ctx = new PoMS.DAL.OracleRepository.OracleEntities())
{
var container = ctx.MetadataWorkspace.GetEntityContainer(ctx.DefaultContainerName, DataSpace.CSpace);
foreach (var set in container.BaseEntitySets)
{
var metadataProperties = set.ElementType.Members.Where(x => x is NavigationProperty).Cast<NavigationProperty>();
foreach (var p in metadataProperties)
{
if (p.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many)
continue;
var k = new Key();
k.TypeName = set.ElementType.Name;
k.NavPropertyName = p.Name;
var assoc = (p.ToEndMember.DeclaringType as AssociationType);
if (assoc.ReferentialConstraints.Count == 1)
{
var dependentProp = assoc.ReferentialConstraints.First().ToProperties.First();
var v = new Value();
v.ScalarPropertyName = dependentProp.Name;
v.EndMemberType = p.ToEndMember.Name;
result.Add(k, v);
}
}
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment