Search code examples
entity-frameworkpocot4edmxcsdl

No schema encountered with 'Base' namespace when running POCO entity generator with a CSDL file which imports a namespace from another CSDL file


I'm getting this error "No schema encountered with 'Base' namespace" when running POCO entity generator with a CSDL file which imports a namespace from another CSDL file.

Both CSDL files have been moved to different folders outside the project folder. This because I had to edit the Administracion.csdl file to import the namespace from the "Base" CSDL file.

The "Administracion.csdl" file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Schema Namespace="Administracion" Alias="Self" p1:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:p1="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
  <Using Namespace="Base"  Alias="Base" />
  <EntityContainer Name="AdministracionEntities" p1:LazyLoadingEnabled="true">
    <EntitySet Name="adm_accesoxperfil" EntityType="Administracion.adm_accesoxperfil" />
    <EntitySet Name="adm_accesoxusuario" EntityType="Administracion.adm_accesoxusuario" />
    <EntitySet Name="adm_accionxnivelseguridadxusuario" EntityType="Administracion.adm_accionxnivelseguridadxusuario" />
    <EntitySet Name="adm_alarmaxperiodopresupuesto" EntityType="Administracion.adm_alarmaxperiodopresupuesto" />
    <EntitySet Name="adm_categoriapredefinidaxbanner" EntityType="Administracion.adm_categoriapredefinidaxbanner" />
    <EntitySet Name="adm_configuraciondetallepresupuesto" EntityType="Administracion.adm_configuraciondetallepresupuesto" />
    <EntitySet Name="adm_configuracionperiodopresupuesto" EntityType="Administracion.adm_configuracionperiodopresupuesto" />
    <EntitySet Name="adm_confirmacionseguridadoperacion" EntityType="Administracion.adm_confirmacionseguridadoperacion" />
    <EntitySet Name="adm_cuenta" EntityType="Base.adm_cuenta" />
    <EntitySet Name="adm_cuentaxmetafinanciera" EntityType="Administracion.adm_cuentaxmetafinanciera" />

I edited the POCO entity generator template to read the CSDL files I've edited instead of reading the EDMX file on the project folder.

The code on the template looks like this:

string csdl = @"path\Administracion.csdl";  
var ItemCollection = new EdmItemCollection(csdl);

When running the template I'm getting the following error:

Error   1   Running transformation: System.Data.MetadataException: Schema specified is not valid. Errors: 
Administracion.csdl(3,4) : error 0160: No schema encountered with 'Base' namespace. Make sure the namespace is correct or the schema defining the namespace is specified.
Administracion.csdl(13,6) : error 0034: Unknown namespace or alias (Base). 

What am I doing wrong? Is it because the CSDL files are in different folders? Where do I have to place them? Can the POCO entity generator template handle with importing namespaces on CSDL files?


Solution

  • The problem behind the error was that I wasn't loading the other CSDL files in the EdmItemCollection. The solution was to load a String[] with the paths of the necessary CSDL files (including the ones with the imported namespaces) to the EdmItemCollection.

    In code, it looks like this:

    List<string> lstCsdlPaths = new List<string>();
    lstCsdlPaths.Add(@"path\Base.csdl");
    lstCsdlPaths.Add(@"path\Administracion.csdl");
    var ItemCollection = new EdmItemCollection(lstCsdlPaths.ToArray());