Click here to Skip to main content
15,886,770 members
Articles / Programming Languages / XML

Rename Visual Studio Projects and Resolve Related Issues for a Silverlight Application

Rate me:
Please Sign up or sign in to vote.
4.67/5 (3 votes)
22 Apr 2012CPOL11 min read 58.6K   236   15  
A step by step guide showing the details of renaming projects and resolving related issues in a Visual Studio 2010 solution for a Silverlight application.

namespace StoreRiaLib.Web.Services
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Data.Entity.Infrastructure;
    using System.Linq;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;
    using StoreRiaLib.Web.Models;


    // Implements application logic using the ProductDbContext 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 ProductDomainService : DbDomainService<ProductDbContext>
    {

        // 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 'Categories' query.
        public IQueryable<Category> GetCategories()
        {
            return this.DbContext.Categories;
        }

        public void InsertCategory(Category category)
        {
            DbEntityEntry<Category> entityEntry = this.DbContext.Entry(category);
            if ((entityEntry.State != EntityState.Detached))
            {
                entityEntry.State = EntityState.Added;
            }
            else
            {
                this.DbContext.Categories.Add(category);
            }
        }

        public void UpdateCategory(Category currentCategory)
        {
            this.DbContext.Categories.AttachAsModified(currentCategory, this.ChangeSet.GetOriginal(currentCategory), this.DbContext);
        }

        public void DeleteCategory(Category category)
        {
            DbEntityEntry<Category> entityEntry = this.DbContext.Entry(category);
            if ((entityEntry.State != EntityState.Deleted))
            {
                entityEntry.State = EntityState.Deleted;
            }
            else
            {
                this.DbContext.Categories.Attach(category);
                this.DbContext.Categories.Remove(category);
            }
        }

        // 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.
        public IQueryable<Product> GetProducts()
        {
            return this.DbContext.Products;
        }

        public IQueryable<Product> GetCategorizedProduct(int categoryId)
        {
            return this.DbContext.Products.Where(e => e.CategoryID == categoryId).OrderBy(e => e.ProductName);
        }
        
        public void InsertProduct(Product product)
        {
            DbEntityEntry<Product> entityEntry = this.DbContext.Entry(product);
            if ((entityEntry.State != EntityState.Detached))
            {
                entityEntry.State = EntityState.Added;
            }
            else
            {
                this.DbContext.Products.Add(product);
            }
        }

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

        public void DeleteProduct(Product product)
        {
            DbEntityEntry<Product> entityEntry = this.DbContext.Entry(product);
            if ((entityEntry.State != EntityState.Deleted))
            {
                entityEntry.State = EntityState.Deleted;
            }
            else
            {
                this.DbContext.Products.Attach(product);
                this.DbContext.Products.Remove(product);
            }
        }
    }
}


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
United States United States
Shenwei is a software developer and architect, and has been working on business applications using Microsoft and Oracle technologies since 1996. He obtained Microsoft Certified Systems Engineer (MCSE) in 1998 and Microsoft Certified Solution Developer (MCSD) in 1999. He has experience in ASP.NET, C#, Visual Basic, Windows and Web Services, Silverlight, WPF, JavaScript/AJAX, HTML, SQL Server, and Oracle.

Comments and Discussions