我想模拟一下WCF数据服务用它的“$metadata”标记做什么。。。也就是说,发送一个CSDL文档,该文档描述了一个现有对象集,该对象集可能(或可能不)是实体框架模型的一部分。事实上,假设EF不是讨论的一部分。。。
我想创建一个服务,检查它可以返回的对象类型,生成一个CSDL文档并将其发送给客户机,以便客户机可以从CSDL生成这些对象(使用EDMGen应该可以)。一旦客户机生成了对象(并加载了生成的程序集),它就可以从服务接收强类型数据。
似乎EDMGen不能用于从POCOs生成CSDL(或EDMX)。。。它可以通过一个数据库连接来实现,您可以从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>