我想模拟 WCF 数据服务使用它的“$metadata”标签所做的事情......也就是说,发送一个 CSDL 文档,该文档描述可能(或可能不是)属于实体框架模型的现有对象集。事实上,假设 EF 不是这个讨论的一部分......
我想创建一个服务来检查它可以返回的对象的类型,生成一个 CSDL 文档并将其发送给客户端,以便客户端可以从 CSDL 代码生成这些对象(使用 EDMGen 应该可以工作)。一旦客户端生成了对象(并加载了生成的程序集),它就可以从服务接收强类型数据。
似乎 EDMGen 不能用于从 POCO 生成 CSDL(或 EDMX)......它可以通过 db-connection 来实现,并且您可以从 CSDL 生成 POCO,但没有其他方式。有没有人知道的方法?
具体例子
鉴于此代码:
public class DirectoryEntry
{
public int Id { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public ICollection<DirectoryEntryProperty> Properties { get; set; }
}
public class DirectoryEntryProperty
{
public int Id { get; set; }
public string Key { get; set; }
public string Value { get; set; }
public DirectoryEntry DirectoryEntry { get ; set; }
}
我想生成这个文档:
<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="DirectoryService" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:ib10="http://www.ideablade.com/edm/2010" ib10:Tag="DirectoryService">
<EntityContainer Name="DirectoryServiceContainer" annotation:LazyLoadingEnabled="true" ib10:GenerateDeveloperClasses="true" ib10:DevForceEnabled="false">
<EntitySet Name="DirectoryEntries" EntityType="DirectoryService.DirectoryEntry" />
<EntitySet Name="DirectoryEntryProperties" EntityType="DirectoryService.DirectoryEntryProperty" />
<AssociationSet Name="DirectoryEntryPropertyDirectoryEntry" Association="DirectoryService.DirectoryEntryPropertyDirectoryEntry">
<End Role="DirectoryEntryProperty" EntitySet="DirectoryEntryProperties" />
<End Role="DirectoryEntry" EntitySet="DirectoryEntries" />
</AssociationSet>
</EntityContainer>
<EntityType Name="DirectoryEntry">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Type="Int32" Name="Id" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<Property Type="String" Name="Name" Nullable="false" />
<Property Type="String" Name="Type" Nullable="false" />
<NavigationProperty Name="Properties" Relationship="DirectoryService.DirectoryEntryPropertyDirectoryEntry" FromRole="DirectoryEntry" ToRole="DirectoryEntryProperty" ib10:Tag="DirectoryEntryPropertyCollectionHelper" />
</EntityType>
<EntityType Name="DirectoryEntryProperty">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Type="Int32" Name="Id" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<NavigationProperty Name="DirectoryEntry" Relationship="DirectoryService.DirectoryEntryPropertyDirectoryEntry" FromRole="DirectoryEntryProperty" ToRole="DirectoryEntry" />
<Property Type="Int32" Name="DirectoryEntryId" Nullable="false" />
<Property Type="String" Name="Key" Nullable="false" />
<Property Type="String" Name="Value" Nullable="false" />
</EntityType>
<Association Name="DirectoryEntryPropertyDirectoryEntry">
<End Type="DirectoryService.DirectoryEntryProperty" Role="DirectoryEntryProperty" Multiplicity="*" />
<End Type="DirectoryService.DirectoryEntry" Role="DirectoryEntry" Multiplicity="1" />
<ReferentialConstraint>
<Principal Role="DirectoryEntry">
<PropertyRef Name="Id" />
</Principal>
<Dependent Role="DirectoryEntryProperty">
<PropertyRef Name="DirectoryEntryId" />
</Dependent>
</ReferentialConstraint>
</Association>
</Schema>