Related list in an entity not visible in Silverlight client

Posts   
 
    
ABOH
User
Posts: 148
Joined: 06-Sep-2011
# Posted on: 28-Sep-2011 05:06:26   

Hello,

I have created a Silverlight RIA project to evaulate LLBLGen. There is a many-to-many relationship between Customer and Product. The database has a join table named CustomerProduct. I've properly created our LLBLGen project and set up the n:n relationship in it. In our domaindatasource, the following query gets the requested data. When I set a breakpoint in the DDS query, I see that the proper data is returned. In particular, the Customer.ProductCollectionViaCustomerProduct list has elements in it. However, when I go to my Silverlight client, and loop through the Customers returned by the query, I do not see Customer.ProductCollectionViaCustomerProduct. If I were using EntityFramework, the first thought is to add [Include] to the metadata, but I don't know where to do this in LLBLGEN.

I'd appreciate your help to figure out this issue.

Thank you!

Mike


DDS QUERY

public IQueryable<CustomerEntity> GetCustomersForAccount(Int64 theAccountId) { var adapter = new DataAccessAdapter(); DataAccessAdapter.SetSqlServerCompatibilityLevel( SD.LLBLGen.Pro.ORMSupportClasses.SqlServerCompatibilityLevel.SqlServer2005); LinqMetaData linq = new LinqMetaData(adapter);

// Query for all the customers in the account and include their products.
// For each product, include its vendor and licenses. var customers = (from c in linq.Customer where c.AccountId == theAccountId select c).WithPath(customerPath => customerPath. Prefetch<ProductEntity>(c => c.ProductCollectionViaCustomerProduct). SubPath(productPath => productPath.Prefetch(l => l.Licenses)). SubPath(productPath => productPath.Prefetch(v => v.Vendor)));

// Used to review the results while debugging. foreach(CustomerEntity customer in customers) { string label = customer.Label; foreach (ProductEntity product in customer.ProductCollectionViaCustomerProduct) { label = product.Label; string vendor = product.Vendor.Label; foreach (LicenseEntity license in product.Licenses) { DateTime expDate = license.ExpirationInUtc; } } }

// Return the results. return customers;

}

SILVERLIGHT CLIENT:

LoadOperation<CustomerEntity> lo = context.Load(context.GetCustomersForAccountQuery(1)); lo.Completed += (s, ea) => { if (!lo.HasError && !lo.IsCanceled) { foreach(CustomerEntity customer in lo.Entities) { //customer.ProductCollectionViaCustomerProduct doesn't exist! } } };

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Sep-2011 12:09:44   

Please check Control your WCF RIA Services code through attributes

Look for: System.ServiceModel.DomainServices.Server.IncludeAttribute

ABOH
User
Posts: 148
Joined: 06-Sep-2011
# Posted on: 29-Sep-2011 01:56:38   

Hello,

Thank you for your quick response. simple_smile

So, I followed your advice and did the following:

Added the following namespaces to the Customer entity in the designer so the data attributes (Include, Composition) would compile.

using System.ComponentModel.DataAnnotations; using System.ServiceModel.DomainServices.Server;

I added the [Composition] attribute via the Designer to CustomerEntity.Licenses so when a Customer is deleted, its licenses will be deleted, too.

I added the [Include] attribute via the Designer to CustomerEntity.ProductCollectionViaCustomerProduct so we can include the products collection in the customer in the Silverlight client.

Now, the attributes are in the generated code, but I get the following compilation error:

--------------------------------
Error   1 Invalid Include specification for member CustomerEntity.ProductCollectionViaCustomerProduct'. Non-projection includes can only be specified on members with the AssociationAttribute applied.
---------------------------------

Could you please tell me how to correct this using your tools? I have details for these classes in my original posting.

I am a beginner with LLBLGEN and am almost done with our evaluation of it. However, it took a while for me to figure out the steps for adding a data attribute and the required namespaces. It would be nice to add these steps to your RIA documentation. simple_smile

Thank you for your help!

Mike

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 29-Sep-2011 11:23:31   

Non-projection includes can only be specified on members with the AssociationAttribute applied

The error is self explanatory. you need to add an AssociationAttribute too.

Please check this link for more details: http://stackoverflow.com/questions/5428358/custom-property-in-ria-service-not-available-on-client