2
votes

i am writing OData service which is built on WebApi asp.net, i am building my own EDM

ODataModelBuilder builder = new ODataModelBuilder();

        builder.Namespace = "Models";

        EntitySetConfiguration<Incident> incident = builder.EntitySet<Incident>("Incidents");
        incident.EntityType.HasKey(c => c.IncidentID);
        incident.EntityType.Property(c => c.Name);
        incident.EntityType.Property(c => c.IncidentType);
        incident.EntityType.Property(c => c.Description);
        incident.HasIdLink(eic =>
        {
            return eic.GenerateSelfLink(false);
        }, false);

        var hasManyComments = incident.EntityType.HasMany(c => c.IncidentComments);
        incident.HasNavigationPropertyLink(hasManyComments, (z, y) =>
        {
            return z.GenerateNavigationPropertyLink(y, false);
        }, false);

        EntitySetConfiguration<IncidentComment> incidentComment = builder.EntitySet<IncidentComment>("IncidentComments");
        incidentComment.EntityType.HasKey(c => c.CommentID);
        incidentComment.EntityType.Property(c => c.IncidentID);
        incidentComment.EntityType.Property(c => c.Content);
        incidentComment.HasIdLink(eic =>
        {
            return eic.GenerateSelfLink(false);
        }, false);

i am testing as client both BreezeJS and wcf data client. when i am trying to get Incident in the network i see that both the incident properties are passed and the comments how ever in the wcf client i get empty collection of comments and also for the Breeze testing, i suspect that the metadata is incorrect, what am i missing

1
why not use the ODataConventionModelBuilder? It automatically creates the model for you(example): ODataConventionModelBuilder modelBuilder = new ODataConventionModelBuilder(); var incidents = modelBuilder.EntitySet<Incident>("Incidents"); var comments = modelBuilder.EntitySet<Incident>("IncidentComment"); - Kiran Challa
cause there are properties i dont want to expose and the only way is add attribute of ignoredatamember. i want to have several types of clients that connect differently and can see different set of data - li-raz
sure...but to ignore properties, you could also do something like this products.EntityType.Ignore(prd => prd.ReleaseDate); - Kiran Challa
but how does it know how to build the navigation property? based on which attributes? - li-raz

1 Answers

0
votes

I think... that the issue may be that the ODataModelBuilder does not YET handle the concept of foreign keys. As such, Breeze can't retrieve the metadata that links an fk to its corresponding navigation property. We've pointed this out to Microsoft and they understand the issue but say this won't be fixed until a later release. This is similar to the issue of Independent associations vs Foreign Key associations that surfaces when MS first released the Entity framework.