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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:18:03+00:00 2026-05-18T23:18:03+00:00

OK, I am mostly a LAMP developer so I am new to the entity

  • 0

OK, I am mostly a LAMP developer so I am new to the entity framework. However, I am familiar with the basics in LINQ and have generated a entity model from my DB. Now here is my requirement:

I have a datagrid on a WinForm that will be refreshed from a data source on a remote server every few seconds as changes to the dataset are made from other sources. Obviously, I’d like to construct a lambda expression to get the right anonymous type to satisfy the columns that needs to be shown in my datagrid. I have done this and here is the result (I’m using a custom datagrid control, btw):

alt text

And my code thus far:

Models.dataEntities objDB = new Models.dataEntities();

var vans = from v in objDB.vans
           select v;

gcVans.DataSource = vans;

OK, so now I have my basic data set. One problem I had is that the “Status” column will show a calculated string based on several parameters in the data set. I added this to my entities via a partial class. As you can see in the screenshot, this is working correctly:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1.Models {

    public partial class van {

        public string van_status {

            get {

                if (this.is_offline == 1) {

                    return "Offline";

                } else if (this.is_prayer_room == 1) {

                    return "In Prayer Room";

                } else {

                    return "TODO: Create statuses";

                }

            }

        }

    }

}

This added property works fine. However, the second I try to project the status in an anonymous type so I can also retrieve the school name, I get an error:

Models.dataEntities objDB = new Models.dataEntities();

var vans = from v in objDB.vans
           select new {

               van_name = v.van_name,
               school_name = v.school.school_name,
               capacity = v.capacity,
               phone = v.phone,
               van_status = v.van_status

           };

gcVans.DataSource = vans;

alt text

So, I have two questions:

1) If I cannot use computed properties of my partial classes in LINQ projections, how am I supposed to show my computed string in my datagrid?

2) Am I even approaching this correctly? When I resolve #1, how would I refresh this data (ie during a timer fire event)? Would I simply call objDB.refresh() and then tell my datagrid to update from the datasource? Does calling that method actually run the lambda expression above or does it load everything from the DB?

Thanks for any assistance with this. Also, if you have any best practices to share that would be awesome! I hope I explained this as thoroughly as you need to provide assistance.

  • 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-18T23:18:03+00:00Added an answer on May 18, 2026 at 11:18 pm

    1) Instead of modifying your EF object with a partial class you could always create your own class that contains your read only property van_status. The code you’ve got would be nearly identical:

    Models.dataEntities objDB = new Models.dataEntities();
    gcVans.DataSource = from v in objDB.vans
               select new DisplayVan {
                   van_name = v.van_name,
                   school_name = v.school.school_name,
                   capacity = v.capacity,
                   phone = v.phone,
               };
    

    The van_status property, since it’s read-only, will not need to be specified in the query.

    2) I’m more a web developer than a desktop developer so I’ll give you my take on how to refresh the grid (it may not be the preferred methodology for fat clients)…

    I’m reluctant to trust .Refresh() methods and hope all works to maximal efficiency and work properly. Instead, encapsulate the code from #1 in a method of your own and invoke it from your timer event firing (or however you choose to implement the periodic refresh).

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

Sidebar

Related Questions

I've mostly worked in MVC1. I'm now working with some MVC2 code. I have
I mostly use Java and generics are relatively new. I keep reading that Java
We mostly tend to following the above best practice. Have a look at String
I've managed to mostly ignore all this multi-byte character stuff, but now I need
I'm mostly familiar with Java, C and C++ in which there are ways to
I am mostly use to using Subversion for my source control. However, my current
my company is very LAMP based as of now, and my management had decided
I'm relatively well versed in designing websites. I mostly go for LAMP where I
Mostly it happens if we open a team project from tfs 2008 or tfs
Basically I have a mostly Ajax-based site. When you load up a result, it

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.