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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:52:34+00:00 2026-05-13T19:52:34+00:00

I would love a solution to my current problem, but I would love EVEN

  • 0

I would love a solution to my current problem, but I would love EVEN MORE if I can understand what that error actually means.

I have LINQ to SQL classes for two tables in my DB: Providers and Assignments. I added the following member to the Provider class:

public IEnumerable<Assignment> Assignments 
    {
        get
        {
            return (new linqDataContext())
                .Assignments
                .Where(a => a.ProviderID == this.ProviderID);
        }
    }

Then, I bind a GridView using a query that pulls from the parent Provider and uses the child member Assignments, like this:

protected void PopulateProviders()
    {
        linqDataContext context = new linqDataContext();
        var list = from p in context.Providers
                   where (p.Assignments.Count(a => a.Category == ddlCategory.SelectedValue) > 0)
                   select p;

        lvProviders.DataSource = list;
        lvProviders.DataBind();
    }

At .DataBind(), when it actually runs the query, it throws the following error:

Member access ‘System.String Category’ of ‘Namespace.Assignment’ not legal on type ‘System.Collections.Generic.IEnumerable`1[Namespace.Assignment].

I’ve tried checking for nulls (a => a != null && a.Category …) but that hasn’t worked. I’m not sure what to try next. I think that, if I knew what the error is trying to tell me, I could find the solution. As it stands, I don’t know why member access would be illegal.

  • 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-13T19:52:34+00:00Added an answer on May 13, 2026 at 7:52 pm

    That Assignments property is all wrong. First of all, property getters should not have side-effects, and more importantly, entity classes should never have reverse dependencies on the DataContext. Linq to SQL has no way to decipher this query; it’s relying on a property that does all sorts of crazy stuff that Linq to SQL can’t hope to understand.

    Get rid of that Assignments property now. Instead of doing that, you need to write this query as a join:

    int category = (int)ddlCategory.SelectedValue;
    var providers =
        from p in context.Providers
        join a in context.Assignments
            on p.ProviderID equals a.ProviderID
            into g
        where g.Count(ga => ga.Category == category) > 0
        select p;
    

    That should do what you’re trying to do if I understood the intent of your code correctly.

    One last side note: You never dispose properly of the DataContext in any of your methods. You should wrap it like so:

    using (var context = new linqDataContext())
    {
        // Get the data here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.