locked
Error when using ServerApplicationContext RRS feed

  • Question

  • I added a class which uses inside the ServerApplicationContext, the class is indirectly consumed by an aspx page.

    The error I'm getting is: 

    The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.

    1) Unable to find any implementation of the contract: 'Microsoft.LightSwitch.BaseServices.Logging.Internal.ILoggingService'

    My class goes as follows :

     public class SalesReportQueries 
        {
            
            public IList<SalesPersonReportPoco> GetSalesPersons()
            {
                ServerApplicationContext ctx = ServerApplicationContext.Current;
                if (ctx == null)
                {
                    ctx = ServerApplicationContext.CreateContext();
                }
                var ReportAdventureWorksData = ctx.DataWorkspace.AdventureWorksData;
                var data =
                  from p in
                      ReportAdventureWorksData.SalesPersons
                  select new
                  SalesPersonReportPoco
                  {
                      SalesPersonId = p.SalesPersonID,
                      EmployeeName = p.Employee.Contact.LastName + " " + p.Employee.Contact.FirstName
                  };
              
                    return data.Execute().ToList<SalesPersonReportPoco>();
    
                }
               
            }

    Any idea?

    Thanks.

    paul.


    paul van bladel

    Saturday, August 24, 2013 8:01 AM

Answers

  • Ok, found the problem :)

    This happened me already a few time now. I forgot the disponse the ServerApplicationContext.

    This is done simply by putting it inside a "using" statement:

    public class SalesReportQueries 
        {
            
            public IList<SalesPersonReportPoco> GetSalesPersons()
            {
                ServerApplicationContext ctx = ServerApplicationContext.Current;
                if (ctx == null)
                {
                    ctx = ServerApplicationContext.CreateContext();
                }
    
    using (ctx)
    {
                var ReportAdventureWorksData = ctx.DataWorkspace.AdventureWorksData;
                var data =
                  from p in
                      ReportAdventureWorksData.SalesPersons
                  select new
                  SalesPersonReportPoco
                  {
                      SalesPersonId = p.SalesPersonID,
                      EmployeeName = p.Employee.Contact.LastName + " " + p.Employee.Contact.FirstName
                  };
              
                    return data.Execute().ToList<SalesPersonReportPoco>();
    
                }
         }      
            }


    paul van bladel

    Saturday, August 24, 2013 8:09 AM