thebringking
thebringking

Reputation: 1359

WebApi OData $select and Getters and Setters

I am using OData on my WebApi2 project, and I am querying a model, who's values are stored in the database as encoded HTML strings-

    public class Document : BaseEntity
    {
        private string _subject;
        public string Subject
        {
            get { return HttpUtility.HtmlDecode(_subject); }
            set { _subject = value; }
        }
   } 

When I query this entity using OData with a $select operation, OData reads the row directly and it doesn't pass through the EF document mapper as the values don't come through decoded. Is there anyway to have some kind of middleware that intercepts the read and decodes the strings for these OData queries?

Upvotes: 1

Views: 310

Answers (1)

Fan Ouyang
Fan Ouyang

Reputation: 2142

No, OData queries actually is became LinqToEntity and query DB to get data if those property is map to DB, change things in model's get method can't help, if the decode result isn't dynamic, you can create a new model and return that, if it is dynamic, may be you can use Open type feature in OData, put your decode result in to dictionary then return.

Then your $select should work.

Upvotes: 1

Related Questions