Does How Do I: Display a chart built on aggregated data code work in C# in RTM?
-
Friday, July 29, 2011 5:27 AM
When I follow the directions at:
in C# of course, this code produces:
Compile complete -- 0 errors, 76 warnings
namespace RIAService { using System; using System.Web; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Data; using System.Linq; using System.ServiceModel.DomainServices.Server; using ApplicationData.Implementation; using System.Data.EntityClient; using System.Web.Configuration; // Implements application logic using the ApplicationDataObjectContext context. // TODO: Add your application logic to these methods or in additional methods. // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access // Also consider adding roles to restrict access as appropriate. // [RequiresAuthentication] // TODO: add the EnableClientAccessAttribute to this class to expose this DomainService to clients. public class RIADomainService : DomainService { private ApplicationDataObjectContext m_context; public ApplicationDataObjectContext Context { get { if (this.m_context == null) { string connString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["_IntrinsicData"].ConnectionString; EntityConnectionStringBuilder builder = new EntityConnectionStringBuilder(); builder.Metadata = "res://*/ApplicationData.csdl|res://*/ApplicationData.ssdl|res://*/ApplicationData.msl"; builder.Provider = "System.Data.SqlClient"; builder.ProviderConnectionString = connString; this.m_context = new ApplicationDataObjectContext(builder.ConnectionString); } return this.m_context; } } // TODO: // Consider constraining the results of your query method. If you need additional input you can // add parameters to this method or create additional query methods with different names. // To support paging you will need to add ordering to the 'Products' query. [Query(IsDefault = true)] public IQueryable<ProductsAndFeatures> GetProductsAndFeatures() { var result = from Products in this.Context.Products select new ProductsAndFeatures { ProductID = Products.Id, ProductName = Products.Name, ProductPrice = Products.Price, Notes = Products.Feature.ToArray().ToString() }; return result; } public class ProductsAndFeatures { [Key] public int ProductID { get; set; } public string ProductName { get; set; } public double ProductPrice { get; set; } public string Notes { get; set; } } } }
I can add the WCF RIA Datasource, but then when I build the project I get errors:

Repro is here:
http://silverlight.adefwebserver.com/files/TestWCFRia_bad.zip
Make Them Ask: That's a LightSwitch App?
http://LightSwitchHelpWebsite.com
All Replies
-
Friday, July 29, 2011 5:44 AMOwner
Hi Michael,
If the project builds, you can ignore the warnings. As Justin explained in another post "You can ignore the errors. They are innocuous. The base project systems do not like to make references from one framework type to another (e.g. desktop CLR to Silverlight CLR), but the Lspkg project does not build an assembly, so it's fine."
When I started getting into building extensions I saw a lot of these warnings. Sometimes they were build dependencies that go away when you build, and sometimes they don't go away at all. After bugging Justin and others several times with my concerns I quickly learned that if it builds, it's all good ;-)
Regards,
Steve Hoag Microsoft aka the V-Bee -
Friday, July 29, 2011 5:50 AM
Note the "+" plus sign before Product and RIAService. I had same issue in another post during B2. I thought this fix was scheduled for RTM. Must not made it.
Had something to do with nested classes. Refactor to move nested class(es) out into namepace I think was recommendation.
- Marked As Answer by ADefwebserverMVP Friday, July 29, 2011 6:18 AM
-
Friday, July 29, 2011 6:14 AMOwnerSo I guess the question is - does it build? I assumed from the line "Compile complete -- 0 errors, 76 warnings" that you are only seeing warnings.
Steve Hoag Microsoft aka the V-Bee -
Friday, July 29, 2011 6:20 AM
That was it, Thanks!
The code that works:
namespace RIAService { using System; using System.Web; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Data; using System.Linq; using System.ServiceModel.DomainServices.Server; using ApplicationData.Implementation; using System.Data.EntityClient; using System.Web.Configuration; public class ProductsAndFeatures { [Key] public int ProductID { get; set; } public string ProductName { get; set; } public double ProductPrice { get; set; } public string Notes { get; set; } } // Implements application logic using the ApplicationDataObjectContext context. // TODO: Add your application logic to these methods or in additional methods. // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access // Also consider adding roles to restrict access as appropriate. // [RequiresAuthentication] // TODO: add the EnableClientAccessAttribute to this class to expose this DomainService to clients. public class RIADomainService : DomainService { private ApplicationDataObjectContext m_context; public ApplicationDataObjectContext Context { get { if (this.m_context == null) { string connString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["_IntrinsicData"].ConnectionString; EntityConnectionStringBuilder builder = new EntityConnectionStringBuilder(); builder.Metadata = "res://*/ApplicationData.csdl|res://*/ApplicationData.ssdl|res://*/ApplicationData.msl"; builder.Provider = "System.Data.SqlClient"; builder.ProviderConnectionString = connString; this.m_context = new ApplicationDataObjectContext(builder.ConnectionString); } return this.m_context; } } // TODO: // Consider constraining the results of your query method. If you need additional input you can // add parameters to this method or create additional query methods with different names. // To support paging you will need to add ordering to the 'Products' query. [Query(IsDefault = true)] public IQueryable<ProductsAndFeatures> GetProductsAndFeatures() { var result = from Products in this.Context.Products select new ProductsAndFeatures { ProductID = Products.Id, ProductName = Products.Name, ProductPrice = Products.Price, Notes = "none" }; return result; } } }
The working project is here:
http://silverlight.adefwebserver.com/files/TestWCFRia_good.zip
-
Friday, July 29, 2011 6:22 AM
So I guess the question is - does it build? I assumed from the line "Compile complete -- 0 errors, 76 warnings" that you are only seeing warnings.
Steve Hoag Microsoft aka the V-Bee
Steve, yes it is working now, I will try to remember to make a note in the tutorial I am working on to tell the readers to ignore the warnings.Thanks!
-
Friday, July 29, 2011 7:25 AMOwnerYes, it's an unfortunate side-effect that the warnings show up. The old adage applies - "if it ain't broke, don't worry about it" (or something like that :-)
Steve Hoag Microsoft aka the V-Bee -
Friday, July 29, 2011 11:19 AMModeratorThe VB code that I used in B2 still works in RTM, but I had also made it more "generic" & reusable though.
(plus ça change, plus c'est la même chose!)
-
Friday, July 29, 2011 12:02 PM
The VB code that I used in B2 still works in RTM, but I had also made it more "generic" & reusable though.
(plus ça change, plus c'est la même chose!)
Yann, do you want to post a link to your version? I can't find it.
-
Monday, August 01, 2011 5:51 PM
Update:
I posted a detailed tutorial showing how to create a WCF RIA Service that connects to the LightSwitch database:
WCF RIA Service: Combining Two Tables

