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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:07:58+00:00 2026-05-11T14:07:58+00:00

I’ve just started learning how to use the Entity Framework to write a very

  • 0

I’ve just started learning how to use the Entity Framework to write a very simple C# network monitoring program – this is a learning exercise to try and ‘drive home’ what I’ve only read about to date. I’m also new to C# and LINQ (just to complicate things further.)

I believe I have the data model suitably normalised but I may be wrong. Visual Studio generates a conceptual model that looks OK. I’ve pluralised the associations and EntitySets where necessary, but I’m struggling to perform what I think is a fairly basic query/projection on the data.

The database contains 3 tables:

[Server]    - A server defined by the user that should be pinged. ServerID    - primary key HostAddress - IP or hostname  [Result]    - A result containing data about the last server test ResultID    - primary key ServerID    - foreign key on [Server].[ServerID] StateID     - an integer used to lookup one of 3 possible Server states TimeStamp   - Time stamp of last ping  [State]     - A lookup table containing an integer -> string mapping. StateID     - a unique key StateLabel  - human-readable string like 'unreachable' or 'OK' or 'timeout' 

I have manually populated the database using a few simple entries – just enough to give me something to work with.

For starters, I would like to present all of the Result data in a ListView on a WinForm. The ListView contains the following static columns:

State | Server Address | Last checked

In theory, the ListView’s data needs to be generated by projecting(?) across each of the 3 tables:

  • The ‘State’ column should display the human-readable [State].[StateLabel] linked from [Result].[StateID]
  • The ‘Server Address’ column should display [Server].[HostAddress] linked from [Result].[ServerID]
  • The ‘Last Checked’ column should display [Result].[TimeStamp]

Since I have no need for the object materialisation and/or change-tracking features of ObjectServices, am I correct in thinking it would be more efficient/correct to use Entity SQL/EntityClient and DbDataReader? If so, what would a suitable Entity SQL query look like?

For what it’s worth, I tried using LINQ to Entities and anonymous types in a method but was thwarted by a lack of understanding on a suitable return type:

var results = from r in _context.Result select new {     State = (from s in _context.State          where s.StateId == r.StateId          select s.StateLabel),     r.ServerReference.Value.HostAddress,     r.TimeStamp };  return results.ToList(); // <- No can do. 

Thanks for your help!

Steve

  • 1 1 Answer
  • 3 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. 2026-05-11T14:07:58+00:00Added an answer on May 11, 2026 at 2:07 pm

    Well you won’t be able to return a list of anonymous types unless you cast them to object and have the signature define the return type as List<object> (or suitable interface). Your other issue is that the subquery for State will actually return an IQueryable instead of a single entry (you can use the First extension method with EF to get the first matching item.) Although if you have the foreign key relationship the model should have setup an navigation property for the state as well and you should be able to use the property attached instead of a subquery. So if you would like to have this as a method call that returns a list of objects you will have to create a type that represents the transform or downcast to object. Otherwise you could do it at the form level (this all depends on your needs) where you are attempting to bind the list.

    public List<object> GetStuff() {     var results = from r in _context.Result     select new     {         State = r.StateNavigationProperty.StateLabel, //If FK         State = _context.State.First(state => state.StateId == r.StateId), //If Not FK         HostAddress = r.ServerReference.Value.HostAddress,         TimeStamp = r.TimeStamp     };      return results.Cast<object>().ToList(); }  ...  myListView.DataSource = GetStuff(); 

    And like I said the other alternative is to either create a class for the transform or bind the list directly to the query.

    public class SimpleStuff {     public string State { get; set; }     public string HostAddress { get; set; }     public DateTime TimeStamp { get; set; } } 

    Then just add the class to the select new ala select new SimpleStuff and change the method signature to reflect the class and remove the cast in the return.

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

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • 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 SVN versus CVS is simple. SVN was developed as a… May 11, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer I would recommend using a transparent button instead of a… May 11, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer When you use Reflection.Emit (and I'm presuming DynamicMethod here), you… May 11, 2026 at 11:52 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

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

Top Members

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.