Dynamically setting IncludeFields

Posts   
 
    
dm0527
User
Posts: 5
Joined: 15-May-2009
# Posted on: 06-Jun-2012 18:08:58   

Environment: C# ASP.NET 3.5 LLBLGen v3.1.0.0

I'm attempting to dynamically set up the list of fields to include when fetching data. I'm using adapter and LLBLGen Linq libraries.

I'm attempting to do it through the Fields collection on an Entity, but I get an error back when I try to use it:

The property 'Fields' isn't mapped to a field or database construct of entity type 'LoanEntity'. Did you mean to call an extension method instead? ('Count' vs. 'Count()') ?

Code:


        public static List<LoanEntity> ProcessLoanQuery(List<SelectField> fields, List<SearchItem> searchItems)
        {
            using (DataAccessAdapter da = GetAdapter())
            {
                LinqMetaData md = new LinqMetaData(da);
                var q = (
                    from l in md.Loan
                    select l
                );

                // TODO - figure out how to dynamically apply .IncludeFields
                LoanEntity empty = new LoanEntity();

                foreach (SelectField field in fields)
                {
                    // doesn't work
                    //q = q.IncludeFields<LoanEntity>(f => f.Fields[field.Field]);
                    
                    // also doesn't work
                    int index = empty.Fields[field.Field].FieldIndex;
                    q = q.IncludeFields<LoanEntity>(f => f.Fields[index]);
                }

                SearchProcessor.ApplySearchCriteria<LoanEntity>(ref q, searchItems);
                return (q as ILLBLGenProQuery).Execute<EntityCollection<LoanEntity>>().ToList();
            }
        }

Anyone have any thoughts / examples on how I might accomplish this?

Thanks in advanced.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 06-Jun-2012 19:09:32   

No "Fields" collection in LinqMetaData. Only properties mapped to fields are there.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 07-Jun-2012 12:22:58   

Linq is for known projections, so you can't do what you want with linq. Use our own low-level api to do this.

Frans Bouma | Lead developer LLBLGen Pro