Skip to content

Instantly share code, notes, and snippets.

@foyzulkarim
Last active December 14, 2016 02:20
Show Gist options
  • Save foyzulkarim/de69373ab5e49d44189f992112c1f71c to your computer and use it in GitHub Desktop.
Save foyzulkarim/de69373ab5e49d44189f992112c1f71c to your computer and use it in GitHub Desktop.
Check whether a specific property is actually a Foreign Key of that model
private static bool IsForeignKey(PropertyInfo property, List<PropertyInfo> allProperties)
{
return allProperties.Where(x => x.CustomAttributes.Any(y => y.AttributeType.Name == "ForeignKeyAttribute")).ToList()
.Any(x =>
x.CustomAttributes.Where(y => y.AttributeType.Name == "ForeignKeyAttribute")
.Any(z => z.ConstructorArguments.Any(a => a.Value.ToString() == property.Name)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment