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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:23:25+00:00 2026-05-19T13:23:25+00:00

I want to query a WCF Data Service and use the resulting information to

  • 0

I want to query a WCF Data Service and use the resulting information to databind it to a DataGridView. All the samples I’ve seen (like this official one) assume the most simple scenario, which is always selecting all columns of a single entity. However, on most cases, I want information from related entities and I don’t want every field for the entity being queried:

  Int32 iIDFilter = 3;
  TestEntities oTestDB = new TestEntities(new Uri("http://desk01:9877/TestEntities/"));
  var oConsulta1 = from a in oTestDB.TBLTable1s
                    where a.IDField1 == iIDFilter
                    select new
                    {
                      IDField1 = a.IDField1,
                      IDField2 = a.TBLTable2.IDField1,
                      IDField3 = a.IDField3,
                      IDField4 = a.TBLTable3.IDField1,
                      IDField5 = a.IDRSGroup,
                      IDField6 = a.TBLTable4.IDField1
                    };
  DataServiceCollection<TBLTable1> eventos = new DataServiceCollection<TBLTable1>(oConsulta1);

On the code above, I’ll get an error, since I can’t create the DataServiceCollection, because I’ve selected some fields of TBLTable1, and also some fields of some related entities. Is there any way around this? Do I always have to select all the fields of an entity, with no related fields, when I use WCF Data Services? Can I at least do a foreach on the result?
Tks

  • 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-19T13:23:25+00:00Added an answer on May 19, 2026 at 1:23 pm

    The limitation is that the query has to return “entities”. The easiest way to get there is to return instances of the classes which represent the entities you’re trying to get. Then you can subset it to only include the properties you want. You also can’t “flatten” the results, so if you want just a subset of the properties on a related entity, you need to project that entity, but only some properties on it. For example (I added a reference to the demo OData.org service):

    DemoService ctx = new DemoService(new Uri("http://services.odata.org/OData/OData.svc/"));
    
    var query = from p in ctx.Products
                select new Product()
                {
                    ID = p.ID,
                    Name = p.Name,
                    Category = new Category()
                    {
                        ID = p.Category.ID,
                        Name = p.Category.Name
                    }
                };
    
    DataServiceCollection<Product> products = new DataServiceCollection<Product>(query);
    
    foreach (var p in products)
    {
        Console.WriteLine(p.Category.Name);
    }
    

    This will run this URL:

    http://services.odata.org/OData/OData.svc/Products()?$expand=Category&$select=ID,Name,Category/ID,Category/Name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two situations in this case: I want to query a WCF service
I query-ing this from entity framework using WCF, and i want to use the
I want DBSession.query(Article).group_by(Article.created.month).all() But this query can't using How do I do this using
I would like to query data given an array to filter by via WCF
I want to invoke a wcf webservice using a url query string. Like if
Is it possible to use the service driven paging feature in WCF Data services
My WCF Data Service includes this: [WebGet] public MyClass GetClass() { return new MyClass();
i want query a file xml with linq, i want get all descendat of
I want to query the name of all columns of a table. I found
I am putting together a WCF Data Service for PatientEntities using Entity Framework. My

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.