chris_dotnet
chris_dotnet

Reputation: 854

Exclude column from WebAPI IQueryable

Is it possible to exclude a column from my WebAPI's IQueryable function? e.g. How would I exclude the property "FirstName" from my people entity:

[HttpGet]
public IQueryable<Contact> GetPeople()
{
    return _contextProvider.Context.People;
}

pseudocoded:

[HttpGet]
public IQueryable<Contact> GetPeople()
{
    return _contextProvider.Context.People.ExcludeColumn("FirstName");
}

Upvotes: 3

Views: 3599

Answers (2)

codeandcloud
codeandcloud

Reputation: 55200

Another method is to decorate the column with Runtime.Serialization.IgnoreDataMember like this.

[Runtime.Serialization.IgnoreDataMember]
public string FirstName { get; set; }

Upvotes: 1

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236208

Project results manually to Contact entity, and do not provide data for FirstName column:

[HttpGet]
public IEnumerable<Contact> GetPeople()
{
    return from p in _contextProvider.Context.People
           select new Contact {
               Id = p.Id,
               LastName = p.LastName
           };
}

BTW I'd create some other specific DTO object which don't have FirstName property.

Upvotes: 7

Related Questions