problem using ExcludeIncludeFieldsList()

Posts   
 
    
John Smith
User
Posts: 6
Joined: 24-Oct-2010
# Posted on: 26-Jan-2011 02:07:50   

I’m a new user and the docs on this feature are crystal clear, however what the docs say and how my code behaves seems to be exactly opposite, so I must be doing something stupid.

If I want to exclude fields I should set ExcludeContainedFields = false, however the resulting query includes everything except the field I want. Setting it to true does the exact opposite.

There is nothing special about the single field I want to fetch (not PK or FK).

The docs clearly say, “When ExcludeContainedFields is set to false, the fields added to the instance of should be seen as the fields to fetch.”

// only include MostRecentTitleReportHistoryId field
ExcludeIncludeFieldsList excludedFields = new ExcludeIncludeFieldsList();
excludedFields.ExcludeContainedFields = false;
excludedFields.Add(AfwOrderFields.MostRecentTitleReportHistoryId);

AfwOrderEntity afwOrderEntity = new AfwOrderEntity(afwOrderId);
adapter.FetchExcludedFields(afwOrderEntity, excludedFields);

Generated Sql query: 
Query: SELECT TOP(@p2) [AfwOrder].[AfwOrderId], [AfwOrder].[FileStorCustomerOrderCounter], [AfwOrder].[FileStorInvoiceCounter], [AfwOrder].[FileStorOrderSheetCounter], [AfwOrder].[FileStorTitleReportCounter], [AfwOrder].[InsertedDate], [AfwOrder].[InsertedUser], [AfwOrder].[IsInstantInvoice], [AfwOrder].[LastUpdatedDate], [AfwOrder].[LastUpdatedUser], [AfwOrder].[OrderKey] FROM [AfwOrder]   WHERE ( ( ( [AfwOrder].[AfwOrderId] IN (@p3))))
Parameter: @p2 : Int64. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 250.
Parameter: @p3 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 2.

// only include MostRecentTitleReportHistoryId field
ExcludeIncludeFieldsList excludedFields = new ExcludeIncludeFieldsList();
excludedFields.ExcludeContainedFields = true;
excludedFields.Add(AfwOrderFields.MostRecentTitleReportHistoryId);

AfwOrderEntity afwOrderEntity = new AfwOrderEntity(afwOrderId);
adapter.FetchExcludedFields(afwOrderEntity, excludedFields);


Generated Sql query: 
Query: SELECT TOP(@p2) [AfwOrder].[AfwOrderId], [AfwOrder].[MostRecentTitleReportHistoryId] FROM [AfwOrder]   WHERE ( ( ( [AfwOrder].[AfwOrderId] IN (@p3))))
Parameter: @p2 : Int64. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 250.
Parameter: @p3 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 2.
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Jan-2011 05:42:11   

The problem is here:

...
adapter.FetchExcludedFields(afwOrderEntity, excludedFields);
..

You are using FetchExcludedFields which means that all the fields that should be excluded now are fetched. You should use the normal Fetch routine:

    ExcludeIncludeFieldsList excludedFields = new ExcludeIncludeFieldsList();
    excludedFields.ExcludeContainedFields = false;
    excludedFields.Add(AfwOrderFields.MostRecentTitleReportHistoryId);

    AfwOrderEntity afwOrderEntity = new AfwOrderEntity(afwOrderId);
    adapter.FetchEntity(afwOrderEntity, null, null, excludedFields);

That's it. If after that you need the other fields, just do this:

adapter.FetchExcludedFields(afwOrderEntity, excludedFields);

Hope helpful

David Elizondo | LLBLGen Support Team
John Smith
User
Posts: 6
Joined: 24-Oct-2010
# Posted on: 26-Jan-2011 23:10:33   

David thank you so much! Everything works perfectly now!