protected virtual Type GetEntityType(string entityName) { Type result = AssemblyReader.FindType( GOCWindows.Instance.LinqToClassesAssembly, GOCWindows.Instance.LinqToSQLClassesNamespace, entityName, false); if (result == null) { throw new NullReferenceException(string.Format("Could not find entity with name {0}.", entityName)); } return(result); }
/// <summary> /// Uses reflection to look for and return a .NET type in the DbContext that is managed by the NKitDbRepository. /// The search is done by looking in the assembly and namespace configured in EntityFrameworkModelsAssembly and EntityFrameworkModelsNamespace settings of the NKitDbRepositorySettings section of the appsettings.json file. /// Returns the .NET entity type from the DbContext. Throws an exception if it is not found. /// </summary> /// <param name="entityName">The name of the entity type to look for.</param> protected virtual Type GetEntityType(string entityName) { Type result = AssemblyReader.FindType(_dbRepositorySettings.EntityFrameworkModelsAssembly, _dbRepositorySettings.EntityFrameworkModelsNamespace, entityName, false); if (result == null) //If the entity type was not found in the specified models assembly and namespace, look for entity type in the current executing assembly in the default core rest models namespace. { string currentAssemblyName = Path.GetFileName(Assembly.GetExecutingAssembly().CodeBase); string RestApiModelsNamespace = typeof(NKitBaseModel).Namespace; result = AssemblyReader.FindType(currentAssemblyName, RestApiModelsNamespace, entityName, false); } if (result == null) { throw new NullReferenceException(string.Format("Could not find entity with name {0}.", entityName)); } return(result); }