WebAPI call for Self-Servicing

Posts   
 
    
larkydoo
User
Posts: 45
Joined: 30-Jun-2008
# Posted on: 22-Apr-2015 22:31:16   

I'm trying to follow the instructions at http://www.llblgen.com/documentation/4.1/LLBLGen Pro RTF/Using the generated code/Adapter/Distributed systems/gencode_webservices.htm and elsewhere on how to serialize to JSON, but all of the examples are using Adapter and I'm using Self-Servicing and don't quite know how to translater. If I had Adapter code as follows:

public IEnumerable<ProductEntity> GetAllProducts()  
{  
    using(var adapter = new DataAccessAdapter())  
    {  
        var metaData = new LinqMetaData(adapter);  
        return metaData.Product.WithPath(p=>p.Prefetch(x=>x.Category)).ToList();    
    }  
}  

and wanted to translate that to SelfServicing, what would it look like?

Thanks!

Laurie

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Apr-2015 07:51:56   

The translation to SelfServicing would be like:

public IEnumerable<ProductEntity> GetAllProducts() 
{ 
        var metaData = new LinqMetaData(); 
    return metaData.Product.WithPath(p=>p.Prefetch(c=>c.Category)).ToList();
}
David Elizondo | LLBLGen Support Team
larkydoo
User
Posts: 45
Joined: 30-Jun-2008
# Posted on: 23-Apr-2015 17:45:30   

It's not finding WithPath. Do I need an include?

Here's my code:

        
public IEnumerable<CategoryLookupEntity> GetCategories()
        {
            var metaData = new LinqMetaData();
            return metaData.CategoryLookup.WithPath(p => p.Prefetch(c => c.Category)).ToList();
        }

At any rate, I was able to use the following code to achieve the effect I wanted.

        public IEnumerable<CategoryLookupEntity> GetCategories(int? id)
        {
            LinqMetaData metaData = new LinqMetaData();
            if (id.HasValue)
            {
                var q = from c in metaData.CategoryLookup
                        where c.ParentId == id.Value
                        select c;
                return q.ToList();
            }
            else
                return metaData.CategoryLookup.ToList();
        }

I used the following page for reference: https://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/Linq/gencode_linq_gettingstarted.htm#LinqMetaData

Thanks!

Laurie

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 23-Apr-2015 21:14:58   

Are you using the following?

using SD.LLBLGen.Pro.QuerySpec;
using SD.LLBLGen.Pro.QuerySpec.SelfServicing;