我想在我的* .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());