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 6191969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:51:47+00:00 2026-05-24T02:51:47+00:00

I have a WCF/REST web service that I’m considering using Linq to SQL to

  • 0

I have a WCF/REST web service that I’m considering using Linq to SQL to return database info from.

It’s easy enough to do basic queries against tables and return rows, for example:

    [WebGet(UriTemplate = "")]
    public List<User> GetUsers()
    {
        List<User> ret = new List<User>(); ;
        using (MyDataContext context = new MyDataContext())
        {
            var userResults = from u in context.Users select u;
            ret = userResults.ToList<User>();
        }

        return ret;
    }

But what if I want to return data from multiple tables or that doesn’t exactly match the schema of the table? I can’t figure out how to return the results from this query, for example:

 var userResults = from u in context.Users
   select new  { u.userID, u.userName, u.userType, 
                 u.Person.personFirstname, u.Person.personLastname };

Obviously the resulting rowset doesn’t adhere to the “User” schema, so I can’t just convert to a list of User objects.

I tried making a new entity in my object model that related to the result set, but it doesn’t want to do the conversion.

What am I missing?

Edit: related question: what about results returned from stored procedures? Same issue, what’s the best way to package them up for returning via the service?

  • 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-05-24T02:51:48+00:00Added an answer on May 24, 2026 at 2:51 am

    You can create a Complex Type and instead of returning Anonymous object you return the Complex Type. When you map stored procedures using function import, you have a option to automatically create a complex type.

    Create a custom class with the properties that you need:

    public class MyTimesheet
    {
        public int Id { get; set; }
        public string Data { get; set; }
    }
    

    Then create it from your Linq query:

    using (linkDataContext link = new linkDataContext())
    {
        var data = (from t in link.TimesheetDetails
                   select new MyTimesheet
                   {
                       Id = t.Id,
                       Data = t.EmployeeId.ToString()
                   }).ToList();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple REST web service in WCF that is declared as follows:
I have a WCF REST web service that is hosted via a service route
I'm trying to expose a simple WCF REST service using data from Linq to
I have a serializable dictionary that I created for a WCF REST web service
I have a WCF/REST Web Service that I'm trying to add a global exception
I have a REStful WCF web service (using a substantially modified WCF Rest Starter
I have made a REST Web service, that works with Visual Studios WCF Test
I have a WCF service that I have to reference from a .net 2.0
I have a WCF Web Service which is referenced from a class library. After
I have developed a sample WCF REST service that accepts that creates an Order

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.