2
Vote

Add support for documentation to ODataConventionModelBuilder

description

This can be done easily by looking for the System.ComponentModel.Description attribute on entities and properties, and using the EDM model's SetDocumentation() method.

comments

HongmeiG wrote Apr 1, 2013 at 8:06 PM

Nice feature request Thargy! Today you could add the documentation yourself after the model is built by the conventional model builder.

raghuramn wrote Apr 9, 2013 at 1:35 AM

private static IEdmModel GetEdmModel()
{
    ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
    builder.EntitySet<Customer>("Customers");
    builder.EntitySet<Order>("Orders");

    IEdmModel model = builder.GetEdmModel();
    DocumentModel(model);

    return model;
}

private static void DocumentModel(IEdmModel model)
{
    foreach (IEdmType edmType in model.SchemaElements.OfType<IEdmType>())
    {
        Type clrType = model.GetAnnotationValue<ClrTypeAnnotation>(edmType).ClrType;

        model.SetDocumentation(edmType, new EdmDocumentation("Summary", "Description"));
    }
}

KevinBurton wrote Sep 5, 2013 at 10:56 PM

So for the slow how is this used? For example one of the resources that I am adding looks like:
        var schedules = modelBuilder.EntitySet<ScheduleRepresentation>("Schedules");
A portion of the ScheduleRepresentation looks like:
public class ScheduleRepresentation
{
    [Key]
    public string Id { get; set; }
    public string Name { get; set; }
    public string TitleType { get; set; }
    public string FolderId { get; set; }
Is it as simple as adding /// comments to each property? If so should they be /// <summary> ?

Thank you.

raghuramn wrote Sep 6, 2013 at 12:23 AM

@Kevin: we don't automatically parse the xml documentation and populate the model with it. The above sample shows how to annotate an EDM model with documentation. You should write code to parse the xml doc file or wherever your documentation lives and annotate your model.