GetDbContextForEntityType() public static method

Gets the appropriate DbContext based on the entity type
public static GetDbContextForEntityType ( Type entityType ) : System.Data.Entity.DbContext
entityType System.Type Type of the Entity.
return System.Data.Entity.DbContext
Esempio n. 1
0
        /// <summary>
        /// Gets the type of the i entity for entity.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="guid">The unique identifier.</param>
        /// <returns></returns>
        public static Rock.Data.IEntity GetIEntityForEntityType(Type entityType, Guid guid)
        {
            var dbContext = Reflection.GetDbContextForEntityType(entityType);

            Rock.Data.IService serviceInstance = Reflection.GetServiceForEntityType(entityType, dbContext);
            if (serviceInstance != null)
            {
                System.Reflection.MethodInfo getMethod = serviceInstance.GetType().GetMethod("Get", new Type[] { typeof(Guid) });
                return(getMethod.Invoke(serviceInstance, new object[] { guid }) as Rock.Data.IEntity);
            }

            return(null);
        }