public static string[] GetKeyNames<T>(DbContext context) where T : class { Type t = typeof(T); ObjectContext objectContext = ((IObjectContextAdapter)context).ObjectContext; MethodInfo method = typeof (ObjectContext).GetMethod("CreateObjectSet", Type.EmptyTypes).MakeGenericMethod(t); -> dynamic objectSet = method.Invoke(objectContext, null); IEnumerable<dynamic> keyMembers = objectSet.EntitySet.ElementType.KeyMembers; string[] keyNames = keyMembers.Select(k => (string)k.Name).ToArray(); return keyNames; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)