Exemplo n.º 1
0
        private string GetKey <K>() where K : class
        {
            System.Data.Entity.Core.Objects.ObjectContext objContext = ((System.Data.Entity.Infrastructure.IObjectContextAdapter)db).ObjectContext;
            System.Data.Entity.Core.Objects.ObjectSet <K> set        = objContext.CreateObjectSet <K>();
            string keyName = set.EntitySet.ElementType.KeyMembers.Select(k => k.Name).First().ToString();

            return(keyName);
        }
Exemplo n.º 2
0
        private String GetPropertyNameKey()
        {
            System.Data.Entity.Core.Objects.ObjectContext objectContext = ((IObjectContextAdapter)context).ObjectContext;
            System.Data.Entity.Core.Objects.ObjectSet <T> set           = objectContext.CreateObjectSet <T>();
            string keyNames = set.EntitySet.ElementType.KeyMembers.Select(k => k.Name).FirstOrDefault();

            return(keyNames);
        }
Exemplo n.º 3
0
        //===============================================================
        public static string GetTableName <T>(this System.Data.Entity.Core.Objects.ObjectContext context) where T : class
        {
            string sql   = context.CreateObjectSet <T>().ToTraceString();
            Regex  regex = new Regex("FROM (?<table>.*) AS");
            Match  match = regex.Match(sql);

            string table = match.Groups["table"].Value;

            return(table);
        }