Brass9.Data.Entity.EFMetaHelper.GetKeysForModelType C# (CSharp) Method

GetKeysForModelType() public static method

Gets the keys for a given Entity model Type, as PropertyInfo objects Extracted from EF GraphDiff, RefactorThis.GraphDiff.Internal.Extensions.GetPrimaryKeyFieldsFor
public static GetKeysForModelType ( Type type, DbContext db ) : IEnumerable
type Type
db DbContext
return IEnumerable
		public static IEnumerable<PropertyInfo> GetKeysForModelType(Type type, DbContext db)
		{
			var metadataWorkspace = ObjectContextForDb(db).MetadataWorkspace;
			var metadata = metadataWorkspace.GetItems<EntityType>(DataSpace.OSpace)
					.SingleOrDefault(p => p.FullName == type.FullName);
			return metadata.KeyMembers
				.Select(k => type.GetProperty(k.Name,
					BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
					.ToList();
		}