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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:45:40+00:00 2026-06-18T11:45:40+00:00

This is a multi-progned question so please bear with me! I have two queries:

  • 0

This is a multi-progned question so please bear with me! I have two queries:

var dynamicResult = Repository.Select<Table1>()
                        .Where(b => b.InactivatedD == null)
                        .Select(b => b.Table2);

var staticResult = Repository.Select<Table2>()
                       .Where(b => b.column == "CONSTANT");

return dynamicResult.Union(staticResult).ToList();

This works fine. Now I have added an additional property to the the Table2 class and have instructed EF to ignore the field within my configuration like so:

Ignore(e => NewColumn);

This too is working well as I can set the field properly without EF throwing an exception. Now I don’t know if there is an easy way to do what I want. In my first query Table1 has a column that I want to use to hydrate this new column on Table2 but I don’t know of an easy way to do this. The only thing I have been able to come up with is:

var dynamicResult = Repository.Select<Table1>()
                        .Where(b => b.InactivatedD == null)
                        .Select(b => new Table2 { Column1 = b.Table2.Column1, NewColumn = b.SomeColumn ... <additional initialization> });

This is a little messy and the initialization would get pretty long since this entity has about 15 columns I’d need to hydrate. I could, of course, just traverse the association between Table2 and Table1 in my property rather than trying to set it in the above query but that seems like additional work and one more query to maintain. Additionally, when using the method above, my union no longer works. If my queries look like this:

var dynamicResult = Repository.Select<Table1>()
                        .Where(b => b.InactivatedD == null)
                        .Select(b => new Table2 { Column1 = b.Table2.Column1, NewColumn = b.SomeColumn })

var staticResult = Repository.Select<Table2>()
                       .Where(b => b.column == "CONSTANT")
                       .Select(b => new Table2 { Column1 = b.Table2.Column1, NewColumn = b.SomeColumn })

return dynamicResult.Union(staticResult).ToList();

I get an exception that the Entity or Complex type, Table 2, can not be constructed by an Entity Framework query which kind of has me at a loss. I understood why I was getting this error before I told EF to ignore the NewColumn but now I am not sure why this error is popping up.

In summation: is there a better way to hydrate my new column then what I have proposed above and can anyone identify why I am unable to union entities created using new from within a query?

Thanks!

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

    It is never allowed to create an entity type in an EF query irrespective of which properties you address. The reason is that EF has no way to track such entities, because it did not materialize them itself.

    You should define a type that looks like Table2, including the new column and project to that type in both queries. You will be able to union the queries.

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

Sidebar

Related Questions

This is probably a multi-part question. Background: we have a native (c++) library that
I use MVC3, in c# I have this multi-line razor code @{ var accessibilityVb
I think this is a multi-part question, so bear with me. Currently all of
My question is, how can do I take this Multi Dim array collection and
In this question: If a form field has multi validators, how to let play
This is the strangest thing! I have a multi-threaded client application written in Python.
I know this is a kind of multi-pronged question, but I'm about to embark
i have this multi dimentional array that i want to print into a table
I need help refactoring this multi-loop thing. Here is what I have: Campaign has_many
I have this multi-line string (quotes included): abc'asdf $(dont-execute-this) foobar'' How would I assign

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.