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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:19:15+00:00 2026-06-06T21:19:15+00:00

My application is based on Entity Framework. I am offering users to query a

  • 0

My application is based on Entity Framework. I am offering users to query a particular table by saving their queries in another table. For example, TopQuery table in database stores all the queries which are popular among users.
These queries are performed on table “TableData”

For test purposed, I have tried the following and it works. The only problem is that it returns all columns where as I would like to use columns that are mentioned by users in their queries.

string queryString =
        @"SELECT VALUE table FROM TestEntities.TableData AS table where table.col1 = 'test'";

    ObjectQuery<TableData> productQuery2 =
        new ObjectQuery<TableData>(queryString, context);

My problem is that if user stores a query in database like this, it doesn’t work.

SELECT table.col1, table.col2, table.col3 FROM TestEntities.TableData AS table where table.col1 = "test"

I get the exception: The specified cast from a materialized System.Data.Objects.MaterializedDataRecord’ to’TestEntities.TableData’type is not valid.

I have also tried this without any luck.

"SELECT it.col1, it.col2 FROM TableData WHERE it.col1 = 'test'"

What should I do in such case?

Regards,

  • 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-06T21:19:17+00:00Added an answer on June 6, 2026 at 9:19 pm

    You will never get ObjectQuery<TableData> once you try to select only subset of columns. Using ObjectQuery<TableData> works only when you select whole entity as your first query did – that is a strongly typed approach enforced by Entity framework.

    ESQL doesn’t support projection in the way Linq-to-entities does (by allowing you to project to a new anonymous or non mapped type). When using projection with ESQL you must work with ObjectQuery<DbDataRecord>.

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

Sidebar

Related Questions

I'm trying to write a generic repository for my Entity Framework based application. Here's
I am very new to Entity Framework and data-based application. Let the Customer data
I have an Entity Framework based MVC application linked to a SQL server. This
My WPF desktop-based application uses ADO.Net Entity Framework in order to connect to SQL
I'm building an Intranet application based on Ext JS and webservices. Users are authorized
Background We have a WinForms application with Entity Framework 4.2 code-first / FluentAPI using
I'm using the Entity Framework for an ASP.NET Web Forms application and I'm wondering
I develop desktop-based WPF-application, that uses SQL Server 2008 R2 Database and ADO.NET Entity
I have a web forms application that uses entity framework, the application is deployed
I am developing an ASP.Net MVC 3 Web application with Entity Framework 4. When

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.