Click here to Skip to main content
15,888,216 members
Articles / Web Development / ASP.NET

Integrate Reporting Services with Silverlight and RIA Services

Rate me:
Please Sign up or sign in to vote.
5.00/5 (8 votes)
28 Jul 2010CPOL3 min read 92.7K   2.3K   52  
Integrate Reporting Services with your Silverlight Line-of-Business applications.

namespace ReportingServicesDemo.Web
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;


    // Implements application logic using the AdventureWorksLT2008Entities 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]
    [EnableClientAccess()]
    public class ADWLTDomainService : LinqToEntitiesDomainService<AdventureWorksLT2008Entities>
    {

        // 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 'Address' query.
        public IQueryable<Address> GetAddress()
        {
            return this.ObjectContext.Address;
        }

        public void InsertAddress(Address address)
        {
            if ((address.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(address, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Address.AddObject(address);
            }
        }

        public void UpdateAddress(Address currentAddress)
        {
            this.ObjectContext.Address.AttachAsModified(currentAddress, this.ChangeSet.GetOriginal(currentAddress));
        }

        public void DeleteAddress(Address address)
        {
            if ((address.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Address.Attach(address);
            }
            this.ObjectContext.Address.DeleteObject(address);
        }

        // 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 'BuildVersion' query.
        public IQueryable<BuildVersion> GetBuildVersion()
        {
            return this.ObjectContext.BuildVersion;
        }

        public void InsertBuildVersion(BuildVersion buildVersion)
        {
            if ((buildVersion.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(buildVersion, EntityState.Added);
            }
            else
            {
                this.ObjectContext.BuildVersion.AddObject(buildVersion);
            }
        }

        public void UpdateBuildVersion(BuildVersion currentBuildVersion)
        {
            this.ObjectContext.BuildVersion.AttachAsModified(currentBuildVersion, this.ChangeSet.GetOriginal(currentBuildVersion));
        }

        public void DeleteBuildVersion(BuildVersion buildVersion)
        {
            if ((buildVersion.EntityState == EntityState.Detached))
            {
                this.ObjectContext.BuildVersion.Attach(buildVersion);
            }
            this.ObjectContext.BuildVersion.DeleteObject(buildVersion);
        }

        // 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 'Customer' query.
        public IQueryable<Customer> GetCustomer()
        {
            return this.ObjectContext.Customer;
        }

        public void InsertCustomer(Customer customer)
        {
            if ((customer.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(customer, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Customer.AddObject(customer);
            }
        }

        public void UpdateCustomer(Customer currentCustomer)
        {
            this.ObjectContext.Customer.AttachAsModified(currentCustomer, this.ChangeSet.GetOriginal(currentCustomer));
        }

        public void DeleteCustomer(Customer customer)
        {
            if ((customer.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Customer.Attach(customer);
            }
            this.ObjectContext.Customer.DeleteObject(customer);
        }

        // 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 'CustomerAddress' query.
        public IQueryable<CustomerAddress> GetCustomerAddress()
        {
            return this.ObjectContext.CustomerAddress;
        }

        public void InsertCustomerAddress(CustomerAddress customerAddress)
        {
            if ((customerAddress.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(customerAddress, EntityState.Added);
            }
            else
            {
                this.ObjectContext.CustomerAddress.AddObject(customerAddress);
            }
        }

        public void UpdateCustomerAddress(CustomerAddress currentCustomerAddress)
        {
            this.ObjectContext.CustomerAddress.AttachAsModified(currentCustomerAddress, this.ChangeSet.GetOriginal(currentCustomerAddress));
        }

        public void DeleteCustomerAddress(CustomerAddress customerAddress)
        {
            if ((customerAddress.EntityState == EntityState.Detached))
            {
                this.ObjectContext.CustomerAddress.Attach(customerAddress);
            }
            this.ObjectContext.CustomerAddress.DeleteObject(customerAddress);
        }

        // 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 'ErrorLog' query.
        public IQueryable<ErrorLog> GetErrorLog()
        {
            return this.ObjectContext.ErrorLog;
        }

        public void InsertErrorLog(ErrorLog errorLog)
        {
            if ((errorLog.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(errorLog, EntityState.Added);
            }
            else
            {
                this.ObjectContext.ErrorLog.AddObject(errorLog);
            }
        }

        public void UpdateErrorLog(ErrorLog currentErrorLog)
        {
            this.ObjectContext.ErrorLog.AttachAsModified(currentErrorLog, this.ChangeSet.GetOriginal(currentErrorLog));
        }

        public void DeleteErrorLog(ErrorLog errorLog)
        {
            if ((errorLog.EntityState == EntityState.Detached))
            {
                this.ObjectContext.ErrorLog.Attach(errorLog);
            }
            this.ObjectContext.ErrorLog.DeleteObject(errorLog);
        }

        // 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 'Product' query.
        public IQueryable<Product> GetProduct()
        {
            return this.ObjectContext.Product;
        }

        public void InsertProduct(Product product)
        {
            if ((product.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(product, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Product.AddObject(product);
            }
        }

        public void UpdateProduct(Product currentProduct)
        {
            this.ObjectContext.Product.AttachAsModified(currentProduct, this.ChangeSet.GetOriginal(currentProduct));
        }

        public void DeleteProduct(Product product)
        {
            if ((product.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Product.Attach(product);
            }
            this.ObjectContext.Product.DeleteObject(product);
        }

        // 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 'ProductCategory' query.
        public IQueryable<ProductCategory> GetProductCategory()
        {
            return this.ObjectContext.ProductCategory;
        }

        public void InsertProductCategory(ProductCategory productCategory)
        {
            if ((productCategory.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(productCategory, EntityState.Added);
            }
            else
            {
                this.ObjectContext.ProductCategory.AddObject(productCategory);
            }
        }

        public void UpdateProductCategory(ProductCategory currentProductCategory)
        {
            this.ObjectContext.ProductCategory.AttachAsModified(currentProductCategory, this.ChangeSet.GetOriginal(currentProductCategory));
        }

        public void DeleteProductCategory(ProductCategory productCategory)
        {
            if ((productCategory.EntityState == EntityState.Detached))
            {
                this.ObjectContext.ProductCategory.Attach(productCategory);
            }
            this.ObjectContext.ProductCategory.DeleteObject(productCategory);
        }

        // 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 'ProductDescription' query.
        public IQueryable<ProductDescription> GetProductDescription()
        {
            return this.ObjectContext.ProductDescription;
        }

        public void InsertProductDescription(ProductDescription productDescription)
        {
            if ((productDescription.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(productDescription, EntityState.Added);
            }
            else
            {
                this.ObjectContext.ProductDescription.AddObject(productDescription);
            }
        }

        public void UpdateProductDescription(ProductDescription currentProductDescription)
        {
            this.ObjectContext.ProductDescription.AttachAsModified(currentProductDescription, this.ChangeSet.GetOriginal(currentProductDescription));
        }

        public void DeleteProductDescription(ProductDescription productDescription)
        {
            if ((productDescription.EntityState == EntityState.Detached))
            {
                this.ObjectContext.ProductDescription.Attach(productDescription);
            }
            this.ObjectContext.ProductDescription.DeleteObject(productDescription);
        }

        // 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 'ProductModel' query.
        public IQueryable<ProductModel> GetProductModel()
        {
            return this.ObjectContext.ProductModel;
        }

        public void InsertProductModel(ProductModel productModel)
        {
            if ((productModel.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(productModel, EntityState.Added);
            }
            else
            {
                this.ObjectContext.ProductModel.AddObject(productModel);
            }
        }

        public void UpdateProductModel(ProductModel currentProductModel)
        {
            this.ObjectContext.ProductModel.AttachAsModified(currentProductModel, this.ChangeSet.GetOriginal(currentProductModel));
        }

        public void DeleteProductModel(ProductModel productModel)
        {
            if ((productModel.EntityState == EntityState.Detached))
            {
                this.ObjectContext.ProductModel.Attach(productModel);
            }
            this.ObjectContext.ProductModel.DeleteObject(productModel);
        }

        // 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 'ProductModelProductDescription' query.
        public IQueryable<ProductModelProductDescription> GetProductModelProductDescription()
        {
            return this.ObjectContext.ProductModelProductDescription;
        }

        public void InsertProductModelProductDescription(ProductModelProductDescription productModelProductDescription)
        {
            if ((productModelProductDescription.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(productModelProductDescription, EntityState.Added);
            }
            else
            {
                this.ObjectContext.ProductModelProductDescription.AddObject(productModelProductDescription);
            }
        }

        public void UpdateProductModelProductDescription(ProductModelProductDescription currentProductModelProductDescription)
        {
            this.ObjectContext.ProductModelProductDescription.AttachAsModified(currentProductModelProductDescription, this.ChangeSet.GetOriginal(currentProductModelProductDescription));
        }

        public void DeleteProductModelProductDescription(ProductModelProductDescription productModelProductDescription)
        {
            if ((productModelProductDescription.EntityState == EntityState.Detached))
            {
                this.ObjectContext.ProductModelProductDescription.Attach(productModelProductDescription);
            }
            this.ObjectContext.ProductModelProductDescription.DeleteObject(productModelProductDescription);
        }

        // 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 'SalesOrderDetail' query.
        public IQueryable<SalesOrderDetail> GetSalesOrderDetail()
        {
            return this.ObjectContext.SalesOrderDetail;
        }

        public void InsertSalesOrderDetail(SalesOrderDetail salesOrderDetail)
        {
            if ((salesOrderDetail.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(salesOrderDetail, EntityState.Added);
            }
            else
            {
                this.ObjectContext.SalesOrderDetail.AddObject(salesOrderDetail);
            }
        }

        public void UpdateSalesOrderDetail(SalesOrderDetail currentSalesOrderDetail)
        {
            this.ObjectContext.SalesOrderDetail.AttachAsModified(currentSalesOrderDetail, this.ChangeSet.GetOriginal(currentSalesOrderDetail));
        }

        public void DeleteSalesOrderDetail(SalesOrderDetail salesOrderDetail)
        {
            if ((salesOrderDetail.EntityState == EntityState.Detached))
            {
                this.ObjectContext.SalesOrderDetail.Attach(salesOrderDetail);
            }
            this.ObjectContext.SalesOrderDetail.DeleteObject(salesOrderDetail);
        }

        // 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 'SalesOrderHeader' query.
        public IQueryable<SalesOrderHeader> GetSalesOrderHeader()
        {
            return this.ObjectContext.SalesOrderHeader;
        }

        public void InsertSalesOrderHeader(SalesOrderHeader salesOrderHeader)
        {
            if ((salesOrderHeader.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(salesOrderHeader, EntityState.Added);
            }
            else
            {
                this.ObjectContext.SalesOrderHeader.AddObject(salesOrderHeader);
            }
        }

        public void UpdateSalesOrderHeader(SalesOrderHeader currentSalesOrderHeader)
        {
            this.ObjectContext.SalesOrderHeader.AttachAsModified(currentSalesOrderHeader, this.ChangeSet.GetOriginal(currentSalesOrderHeader));
        }

        public void DeleteSalesOrderHeader(SalesOrderHeader salesOrderHeader)
        {
            if ((salesOrderHeader.EntityState == EntityState.Detached))
            {
                this.ObjectContext.SalesOrderHeader.Attach(salesOrderHeader);
            }
            this.ObjectContext.SalesOrderHeader.DeleteObject(salesOrderHeader);
        }

        public IQueryable<Orders> GetOrderDetails(int OrderID)
        {
            AdventureWorksLT2008Entities adw = new AdventureWorksLT2008Entities();

            var query = from c in adw.SalesOrderDetail.Include("Product")
                        where c.SalesOrderID == OrderID
                        select new Orders { OrderID = OrderID, OrderDetailsID = c.SalesOrderDetailID, Product = c.Product.Name, Quantity = c.OrderQty, UnitPrice = c.UnitPrice, UnitPriceDiscount = c.UnitPriceDiscount, LineTotal = c.LineTotal };

            return query;
        }
    }
}


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer Sigo S.A.
Venezuela Venezuela
Ernesto Herrera is a Senior Developer, Architect with more than 12 years experience, actually working with Silverlight Line-of-Bussiness Applications, he holds a MCTS Web Application 2.0 Certification, and have a wide experience with sql server since the 6.5 version, on his free time he likes to play tennis with his wife,kids and friends, also enjoy playing Wii with his sons, he works at Sigo S.A., a retail business located at Margarita Island, Venezuela.

Comments and Discussions