微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 由于名称空间未知,关键字“使用”,运行转换失败

我想在我的* .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时,运行工具会抛出转换错误

Running transformation: No schema encountered with
‘BooksModel.Extended’ namespace. Make sure the namespace is correct or
the schema defining the namespace is specified.

Running transformation: UnkNown namespace or alias
(BooksModel.Extended).

我像这样加载我的CSDL:

var inputFile = @"CSDL_NAME.csdl";
var ItemCollection = loader.CreateEdmItemCollection(inputFile);

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

解决方法

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

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐