0
votes

I am working on an Odata v4 project and wish to return a field from another table in my result set.

So I have 2 tables

Account: Id, Name, Address, ColorCode,

Product: Id, AccountId

AccountId is a foreign key mapped to the Id field in the Account table

I have the following partial class

    public partial class Product

    {   
        public string ColorCode {
            get { return Account.ColorCode; }
        }

public DateTimeOffset? Edmcreated
        {
            get
            {
                return created ;
            }
        }

    }

And my controller:

 [EnableQuery(PageSize = 200)]
    public IQueryable<Product > Get()
    {
        return _db. Product.AsQueryable();
    }

This returns data from the Product data entity but I cant seem to get the ColorCode field in the result set.

How can I achieve the above

1
can open type and dynamic property help you? asp.net/web-api/overview/odata-support-in-aspnet-web-api/…Sam Xu

1 Answers

1
votes

Please refer to my answer to your other question: How to join 2 entities in Odata model builder

And in addition, you don't need to write anything specific for the $expand and $select in the request URL mentioned in that answer. The EnableQuery attribute in the ProductsController handles that for you correctly.