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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:42:15+00:00 2026-06-02T11:42:15+00:00

With a plain connection to SQL Server, you can specify what columns to return

  • 0

With a plain connection to SQL Server, you can specify what columns to return in a simple SELECT statement.

With EF:

Dim who = context.Doctors.Find(3) ' Primary key is an integer

The above returns all data that entity has… BUT… I would only like to do what you can with SQL and get only what I need.

Doing this:

 Dim who= (From d In contect.Doctors
                     Where d.Regeneration = 3
                     Select New Doctor With {.Actor = d.Actor}).Single

Gives me this error:

The entity or complex type XXXXX cannot be constructed in a LINQ to Entities query.

So… How do I return only selected data from only one entity?

  • 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-06-02T11:42:17+00:00Added an answer on June 2, 2026 at 11:42 am

    The best way to do this is by setting the wanted properties in ViewModel “or DTO if you’re dealing with upper levels”
    Then as your example the ViewModel will be:

    public class DoctorViewModel{
    public string Actor {get;set;}
    // You can add as many properties as you want
    }
    

    then the query will be:

    var who = (From d In contect.Doctors
                         Where d.Regeneration = 3
                         Select New DoctorViewModel {Actor = d.Actor}).Single();
    

    Sorry i wrote the code with C# but i think the idea is clear 🙂

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

Sidebar

Related Questions

My applications runs queries against a sql server database. In many cases I can
given a plain text file, how can I do, using bash, awk, sed, etc,
I need to get some sensitive data from an Oracle server to a SQL
I really don't like the concept of opening my SQL server(s) to the internet
I have a server (SQL Server 2005) with multiple archive databases (1 per quarter
I tried to create a database maintenance plan with SQL Server Management Studio with
I'm trying to connect to SQL Server using Windows authentication. The code works fine
When I try to create a new Maintenance Plan in SQL Server, I get
I use C# and SQL Server 2005 and I need a recommendation on how
I am going to use SQL Server in my project, for that I want

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.