Je voudrais simuler ce que fait WCF Data Services avec sa balise "$ metadata" ... c'est-à-dire, envoyer un document CSDL qui décrit un ensemble existant d'objets qui peuvent (ou non) faire partie d'un modèle Entity Framework. En fait, supposons que l'EF ne fait pas partie de cette discussion ...Comment générer par programmation CSDL ou EDMX à partir d'un ensemble d'objets POCO existants
Je veux créer un service qui inspecte le type d'objets qu'il peut retourner, génère un document CSDL et l'envoie au client de sorte que le client peut coder-gen ces objets de la CSDL (en utilisant EDMGen devrait fonctionner). Une fois que le client a généré les objets (et chargé l'assemblage généré), il peut recevoir des données fortement typées du service.
Il ne semble pas que EDMGen puisse être utilisé pour générer des CSDL (ou EDMX) à partir de POCO ... il peut le faire à partir d'une connexion DB et vous pouvez générer des POCO depuis CSDL, mais pas dans l'autre sens. Y a-t-il un moyen que tout le monde connaisse?
béton Exemple
Vu ce code:
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; }
}
J'aimerais générer ce document:
<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>
Je pense que vous avez probablement raison, j'espérais juste trouver un support d'outillage pour cela. –