Exemple #1
0
        /// <summary>
        /// This method will invoke the Breezer.WebApi.EFContextProvider extract the csdl fot the type
        /// </summary>
        /// <param name="type">The type to extract the csdl for</param>
        /// <returns>The metadata, or an empty string</returns>
        /// <remarks>
        /// When using a DbFirst approach EF thwros two kind of exceptions:
        /// 1. InvalidOperationException is there is no connection string for the DbContext we are working on.
        /// 2. UnintentionalCodeFirstException if it finds the connection string for the DbContext.
        ///     UnintentionalCodeFirstException inherits from InvalidOperationException
        /// </remarks>
        private static string GetMetadataFromType(Type type)
        {
            try
            {
                if (type.BaseType == typeof(System.Data.Entity.DbContext) || type == typeof(ObjectContext)) //project is using EF6
                {
                    var providerType = typeof(EFContextProvider <>).MakeGenericType(type);
                    var provider     = (ContextProvider)Activator.CreateInstance(providerType);
                    var metadata     = provider.Metadata();

                    return(metadata);
                }
                else if (type.BaseType == typeof(Microsoft.EntityFrameworkCore.DbContext)) //project is using EF Core
                {
                    var provider = (Microsoft.EntityFrameworkCore.DbContext)Activator.CreateInstance(type);
                    var pm       = new EFPersistenceManager <Microsoft.EntityFrameworkCore.DbContext>(provider);
                    var metadata = pm.Metadata();

                    return(metadata);
                }
                else
                {
                    Console.WriteLine("Could not interpret database context");
                    return(null);
                }
            }
            //catch (InvalidOperationException iex) // This is might be because we have a DbFirst DbContext, so let's try it out.
            //{
            //    try {
            //        return EFContextProvider<object>.GetMetadataFromDbFirstAssembly(type.Assembly, Options.ResourcePrefix);
            //    }
            //    catch (Exception ex) {
            //        Console.WriteLine("An exception was thrown while processing the dbfirst assembly {0}. {1}", type.Assembly.FullName, ex);
            //    }
            //}
            catch (Exception ex)
            {
                Console.WriteLine("An exception was thrown while processing {0}. {1}", type.FullName, ex);
            }
            return(string.Empty);
        }
Exemple #2
0
 //breeze specific methods
 public string Metadata()
 {
     return(_persistenceManager.Metadata());
 }