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

  • Home
  • SEARCH
  • 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 745831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:37:44+00:00 2026-05-14T09:37:44+00:00

// From my form BindingSource bs = new BindingSource(); private void fillStudentGrid() { bs.DataSource

  • 0

// From my form

BindingSource bs = new BindingSource();

private void fillStudentGrid()
{
     bs.DataSource = Admin.GetStudents();
     dgViewStudents.DataSource = bs;
}

// From the Admin class

public static List<Student> GetStudents()

{
    DojoDBDataContext conn = new DojoDBDataContext();

    var query =
        (from s in conn.Students
         select new Student
         {
             ID = s.ID,
             FirstName = s.FirstName,
             LastName = s.LastName,
             Belt = s.Belt
         }).ToList();

    return query;
}

I’m trying to fill a datagridview control in Winforms, and I only want a few of the values. The code compiles, but throws a runtime error:

Explicit construction of entity type ‘DojoManagement.Student’ in query is not allowed.

Is there a way to get it working in this manner?

  • 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-14T09:37:44+00:00Added an answer on May 14, 2026 at 9:37 am

    You already have an IEnumerable<Student> instance and you cannot project entities from a query for the reasons described here)

    You also don’t need to create a list to bind to this data source – you can greatly simplify your method by changing it to this:

    public static IEnumerable<Student> GetStudents()
    {
        return new DojoDBDataContext().Students;
    }
    

    There is no reason to project a new instance to only map a few of the properties, by executing the query you are returning all the values anyhow and your projection doesn’t save you anything. If you really want to only return a few values from this query for the purposes of information hiding you could do this:

    public static IEnumerable<Object> GetStudents()
    {
        DojoDBDataContext conn = new DojoDBDataContext();
    
        return conn.Students
                   .Select(s => new {
                       ID = s.ID,
                       FirstName = s.FirstName,
                       LastName = s.LastName,
                       Belt = s.Belt 
                   });
    }
    

    Edit: If you aren’t using C# 4 you will have to cast the contents of the IEnumerable<T> to Object explicitly. Only C# 4 supports covariance for IEnumerable<T>. So if you are using C# 3 you will have to do this:

    public static IEnumerable<Object> GetStudents()
    {
        DojoDBDataContext conn = new DojoDBDataContext();
    
        return conn.Students
                   .Select(s => new {
                       ID = s.ID,
                       FirstName = s.FirstName,
                       LastName = s.LastName,
                       Belt = s.Belt 
                   }).Cast<Object>();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 530k
  • Answers 530k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For a central starting point for Jet Replication, see my… May 16, 2026 at 11:42 pm
  • Editorial Team
    Editorial Team added an answer I think this is what you're looking for: SELECT c.AgentId,… May 16, 2026 at 11:42 pm
  • Editorial Team
    Editorial Team added an answer No, it does not. And will not. If you're coming… May 16, 2026 at 11:42 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a form which contains a DataGridView, a BindingSource, a DataTable, and a
I have a base form class that contains a method that returns a DataTable:
I have a function for fetching data from a database via a dataset public
Hoo boy. A weird one I guess! getting input from a form, I want
Here is a test framework to show what I am doing: create a new
How can I implement a form with simple components (text boxes, comboboxes) bound to
how I can access a DataSet and it's TablesData (s) to add/delete/edit rows from
I have a form that is validated by js when the user submits it.
I have three pages as follows: 1> Form.php // users enter information, such as
I am trying to save data to a database on a button push, but

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.