Exclude/Include Fields in FetchEntityCollection

Posts   
 
    
Posts: 10
Joined: 11-Dec-2008
# Posted on: 05-Oct-2019 15:02:58   

Hi,

I am trying to fetch only TWO fields from database but following code is returning all fields. Can someone point out what I am doing wrong?

public IHttpActionResult Get() {

        var includedFields = new ExcludeIncludeFieldsList();
        includedFields.ExcludeContainedFields = false;
        includedFields.Add(CourseGroupFields.CourseGroupId);
        includedFields.Add(CourseGroupFields.Name);

        var collection = new EntityCollection<CourseGroupEntity>();

        // fetch a collection of coursegroups
        var courseGroups = new EntityCollection<CourseGroupEntity>();
        var sorter = new SortExpression(CourseGroupFields.Name | SortOperator.Ascending);


        using (var adapter = new DataAccessAdapter())
        {

            adapter.FetchEntityCollection(courseGroups, null, 0, sorter, null, includedFields);
            //adapter.FetchExcludedFields(courseGroups, includedFields);

        }

        return Ok(courseGroups);
    }
daelmo avatar
daelmo
Support Team
Posts: 8152
Joined: 28-Nov-2005
# Posted on: 07-Oct-2019 07:59:30   

Hi there,

The code looks ok.

Posts: 10
Joined: 11-Dec-2008
# Posted on: 13-Oct-2019 19:22:43   

Yup, you're right - The code is 100% OK. I got confused as all field names were returned. However, after careful insight, I found that data for only INCLUDED fields was returned.

daelmo avatar
daelmo
Support Team
Posts: 8152
Joined: 28-Nov-2005
# Posted on: 14-Oct-2019 08:17:10   

softsurgeon wrote:

Yup, you're right - The code is 100% OK. I got confused as all field names were returned. However, after careful insight, I found that data for only INCLUDED fields was returned.

Yes, you will always see the fields, the difference is that the data is not fetched so those fields are there but empty (or default values). Good you figured it out simple_smile