API Question - OData

Topics: ASP.NET Web API
Jul 29, 2013 at 7:14 PM
hi
i trying to figure out what is the diff between
HasNavigationPropertiesLink and HasNavigationPropertyLink
also HasEditLink --> where can i found some examples for all of it?

for example
in
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;

namespace WebApplication1.Models
{
public class Product
{
    public int ID { get; set; }
    public string Name { get; set; }

    public int StoreID { get; set; }

    public Store Store { get; set; }
}

public class Store
{
    public int ID { get; set; }
    public string Name { get; set; }

    public ICollection<Product> Products { get; set; }
}
}

i have created

ODataModelBuilder builder = new ODataModelBuilder();
        EntitySetConfiguration<Product> ProductconfigSet = builder.EntitySet<Product>("Product");
        ProductconfigSet.HasIdLink(eic => eic.GenerateSelfLink(false), true);
        ProductconfigSet.EntityType.HasKey(s => s.ID);
        ProductconfigSet.EntityType.Property(s => s.Name);
        ProductconfigSet.EntityType.Property(s => s.StoreID);
        var hasopt = ProductconfigSet.EntityType.HasOptional(s => s.Store);
        ProductconfigSet.HasNavigationPropertyLink(hasopt, (z, y) =>
        {
            return z.GenerateNavigationPropertyLink(y, false);
        }, false);

        EntitySetConfiguration<Store> StoreconfigSet = builder.EntitySet<Store>("Store");
        StoreconfigSet.HasIdLink(eic => eic.GenerateSelfLink(false), true);
        StoreconfigSet.EntityType.HasKey(s => s.ID);
        StoreconfigSet.EntityType.Property(s => s.Name);

        var hasMany = StoreconfigSet.EntityType.HasMany(s => s.Products);
        StoreconfigSet.HasNavigationPropertyLink(hasMany, (z, y) =>
        {
            return z.GenerateNavigationPropertyLink(y, false);
        }, false);



        builder.Namespace = "WebApplication1.Models";

        return builder.GetEdmModel();

is it ok - regarding the relation
Jul 29, 2013 at 7:43 PM
HasNavigationPropertiesLink is a bulk operation. It configures the navigation link for all the navigation properties declared till then. HasNavigationPropertyLink configures the navigation link for just that property.

Your model builder code looks fine. But I don't see a reason why you are not using ODataConventionModelBuilder. Most of the configuration that you are doing can be inferred automatically by the Convention model builder and would save you code. Generally, all you need tell it is the entity sets you have. for instance, in your case,
ODataModelBuilder builder = new ODataModelBuilder();
builder.EntitySet<Product>("Product");
build.EntitySet<Store>("Store");
builder.Namespace = "WebApplication1.Models";
return builder.GetEdmModel();
should be enough.
Jul 29, 2013 at 7:47 PM
i am not using the ODataConventionModelBuilder cause in my real scenario i have DTO which i dont want to expose all the properties and i cannot use datacontract for the datamember ignore, so i dont have othe choise