我想在 *.csdl 中使用“Using”元素来导入其他命名空间,并使用 POCO 来转换对象。

我使用的 CSDL 如下所示:

<Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm"
          xmlns:cg="http://schemas.microsoft.com/ado/2006/04/codegeneration"
          xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator"
          Namespace="BooksModel" Alias="Self">

    <Using Namespace="BooksModel.Extended" Alias="BMExt" />

    <EntityContainer Name="BooksContainer" >
      <EntitySet Name="Publishers" EntityType="BooksModel.Publisher" />
    </EntityContainer>

    <EntityType Name="Publisher">
      <Key>
        <PropertyRef Name="Id" />
      </Key>
      <Property Type="Int32" Name="Id" Nullable="false" />
      <Property Type="String" Name="Name" Nullable="false" />
      <Property Type="BMExt.Address" Name="Address" Nullable="false" />
    </EntityType>

</Schema>

(http://msdn.microsoft.com/en-us/library/bb738545.aspx)

但是,当我使用模板 (POCO) 来转换我的 CSDL 时,运行工具会引发转换错误:



我像这样加载我的 CSDL:
var inputFile = @"CSDL_NAME.csdl";
var ItemCollection = loader.CreateEdmItemCollection(inputFile);

如何修改模板以包含未知命名空间?

最佳答案

错误背后的问题是您没有在 EdmItemCollection 中加载其他 CSDL 文件。解决方案是将带有必要 CSDL 文件(包括具有导入命名空间的文件)的路径的 String[] 加载到 EdmItemCollection。

在代码中,它看起来像这样:

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

关于c# - 由于使用关键字 "using"的未知命名空间,运行转换失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10224104/

10-08 22:52