Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8308319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:46:25+00:00 2026-06-08T18:46:25+00:00

I am trying to return a custom class from my wcf service. My codes

  • 0

I am trying to return a custom class from my wcf service. My codes are below and getting error.

The server encountered an error processing the request. The exception message is ‘The property ‘UserList’ on type ‘DealerModel’ is not a valid property. Properties whose types are collection of primitives or complex types are not supported.’. See server logs for more details. The exception stack trace is:

I am trying to get a json value like below;

<Dealer>
        <DealerName/>
        <DealerAdress/>
        <Users>
              <FirstName/>
              <LastName/>
              <FirstName/>
              <LastName/>
        </Users>
</Dealer>

My codes

using System;
using System.Linq;
using System.Data.Objects;
using System.Data.Objects.DataClasses;

public class DataModel:IDisposable
{
    private xModel.xEntities _dbContext = new xSocialModel.xEntities();

    public DataModel()
    {
        Users = from e in _dbContext.Users
                select new UserModel
                {
                    UserID = e.UserID,
                    Firstname = e.Firstname,
                    Lastname = e.Lastname
                };

        Dealers = from e in _dbContext.Dealers
                  select new DealerModel
                  {
                      DealerID = e.DealerID,
                      DealerName = e.Name,
                      DealerAddress = e.Address,
                      UserList = e.Users
                  };

    }

    /// <summary>Returns the list of users.</summary>
    public IQueryable<UserModel> Users { get; private set; }

    public IQueryable<DealerModel> Dealers { get; private set; }


    void IDisposable.Dispose()
    {
        _dbContext.Dispose();
    }
}



    using System;
    using System.Data.Services.Common;
    using System.Runtime.Serialization;
    using System.Collections.Generic;
    using System.ServiceModel;
    using System.Data.Objects.DataClasses;
    using System.Linq;

    /// <summary>Represents a User.</summary>

    [DataServiceKey("UserID")]
    public class UserModel
    {
        public Guid UserID { get; set; }

        public string Firstname { get; set; }

        public string Lastname { get; set; }

    }


    [DataServiceKey("DealerID")]
    public class DealerModel
    {
        public Guid DealerID { get; set; }

        public string DealerName { get; set; }

        public string DealerAddress { get; set; }

        **public EntityCollection<xModel.User> UserList { get; set; }**

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:46:27+00:00Added an answer on June 8, 2026 at 6:46 pm

    I had a lot of trouble with this as well. Projection doesn’t seem to work as nicely as RIA services used it. I’ll go ahead and assume you are using Entity Framework. The only way I’ve found to do this is to create Complex Types in your edmx.

    To do this, open your EDMX, then select the Model Browser in the right pane. Under the “Model” node, you will see “Complex Types”, right click and select “Create Complex Type”. In the same window then, you can name your type and give it various properties of canned types.

    From your question it appears you have a property that is a list. I have not been able to create these complex types with properties that contain other entities. Not saying it isn’t possible just that I haven’t been able to figure it out.

    Now in your DataService, create a service method with a return type of your new complex type. In the service method, use projection to fill the object (or list) and return it as you would any other entity. On the front end you will need to call it like a Service Method instead of an entity, but otherwise the JSON will look similar to other entity queries.

    Sam Mueller has a very nice blog on using this technique, check it out: http://samuelmueller.com/2009/11/working-with-projections-and-dtos-in-wcf-data-services/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement a custom class for dataannotations that retrieves error messages from
i'm trying to return a custome object from a web service object returned only
For a custom derived class Vector2 from flash.geom.Point, when trying to override the clone()
I have a WCF service where I am trying to return a List (where
i'm trying to do this from inside the .m of a custom view class
I have a WCF Service Library containing a custom ServiceHostFactory derived from DefaultServiceHostFactory. I
I'm trying to return a custom 404 page using IIS6. (I have a site
Im trying to return the value that a $ajax call returns, from a function
I was trying to create a custom combobox that inherited from ComboBox, but I've
This is making me crazy... I'm trying to have a custom WCF auth token

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.