tags:

views:

130

answers:

1

Hi,

I have a solution that I have designed with 5 layers.

They are:

  • UI/Presentation Layer
  • Service Layer
  • Business Logic Layer
  • Data Access Layer
  • DTO/Common Layer (IQUTECHDTO)

I want to pass the DTO to the UI. Below is the service layer that exposes a method GetVendors which I want to return the VendorDTO. This object will populate a drop down box.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
using IQUTechDTO;
using IQUTECHDAL;

namespace BusinessApplication6.Web.Services
{

    public class Foos
    {

        [Key]

        public int FooId { get; set; }

        public string Name { get; set; }

    }

    // TODO: Create methods containing your application logic.
    [EnableClientAccess()]
    public class BillService : DomainService
    {

        public IEnumerable<Foos> GetFoos()
        {
            return new List<Foos> { new Foos { FooId = 42, Name = "Fred" } };
        }

        [Query]
        public IEnumerable<VendorDTO> GetVendors()
        {
            return new List<VendorDTO> { new VendorDTO { VendorID = 42 } };  
        }

    }
}

On the UI .cs file when I try and create an object of type VendorDTO I cannot. I was however able to access the Foo object from the UI Layer.

The VendorDTO was marked as serialazble but it does however reside in a seperate project (IQUTECHDTO)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.ServiceModel.DomainServices;
using System.ServiceModel.Web;


namespace IQUTechDTO
{
    public enum LoadStatus
    {
     Initialized = 0,
     Ghost = 1,
     Loaded = 2
    }

    [Serializable]
    public class VendorDTO
    {
        /// <summary>
        ///DTO for the 'Vendor' object.
        /// </summary>

        public VendorDTO()
        {
            this.loadStatus = LoadStatus.Initialized;
        }

        ///<summary>
        /// Copy constructor
        ///</summary>
        public VendorDTO(VendorDTO sourceDTO)
        {
            loadStatus = sourceDTO.loadStatus;
            VendorID = sourceDTO.VendorID;
            VendorName = sourceDTO.VendorName;
            VendorAddress1 = sourceDTO.VendorAddress1;
            VendorAddress2 = sourceDTO.VendorAddress2;
            VendorCity = sourceDTO.VendorCity;
            VendorState = sourceDTO.VendorState;
            VendorEmail = sourceDTO.VendorEmail;
            VendorPhone = sourceDTO.VendorPhone;
            VendorPOC = sourceDTO.VendorPOC;
            VendorRegion = sourceDTO.VendorRegion;
        }

        public LoadStatus loadStatus;

        [Key]
        public int VendorID { get; set; }
        public string VendorName;
        private string VendorAddress1;
        private string VendorAddress2;
        private string VendorEmail;
        private string VendorPhone;
        private string VendorCity;
        private string VendorState;
        private string VendorPOC;
        private string VendorRegion;

    }
}

Below is the UI Class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using BusinessApplication6.Web.Services;
using System.ServiceModel.DomainServices.Client;
using BusinessApplication6.Web;


namespace BusinessApplication6.Views.BOM
{
    public partial class BOMCRUD : Page
    {
        public BOMCRUD()
        {
            InitializeComponent();
            LoadTree();


        }

        public void LoadTree()
        {
            BillContext newCon = new BillContext();


            //This works
            Foos fooobj = new Foos();

            //This doesnt work
            VendorDTO vendorobj = new VendorDTO();

        }



        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }



    }
}

Why will it not let me access this object.

Your help would be greatly appreciated.

Regards, Tom

A: 

The UI class has doesn't have a reference to IQUTECHDTO like the Foos class does(in BusinessApplication6.Web).

DaveB
When I try to add a project reference to IQUTECHDTO it says that you can only add project references to other silverlight projects in this solution. That happens when I try to add the reference on the UI Layer to the DTO Library.
TommyK
@TommyK - Since you are using Silverlight, your DTO should be a Silverlight Class Library. You could then LINK to one .cs file from the server and the client side as long as you have no code that is not supported by Silverlight. Take a look at http://www.netfxharmonics.com/2008/12/Reusing-NET-Assemblies-in-Silverlight for some ideas.
DaveB