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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:27:23+00:00 2026-06-03T01:27:23+00:00

I have the following 2 tables defined in a SQL Server database: CREATE TABLE

  • 0

I have the following 2 tables defined in a SQL Server database:

  CREATE TABLE [dbo].[FinancialItem](
    [Id][bigint] identity(1,1) NOT NULL,
    [TranId] [int] NOT NULL,
    [Installment][int] NOT NULL,
    [Amount][decimal](16,2) NOT NULL
   CONSTRAINT [FinancialItem0] PRIMARY KEY
   (
     [Id] ASC
   )

  CREATE TABLE [dbo].[FinancialItemHistory](
    [Id][bigint] NOT NULL,
    [TranId] [int] NOT NULL,
    [Installment][int] NOT NULL,
    [Amount][decimal](16,2) NOT NULL
   CONSTRAINT [FinancialItemHistory0] PRIMARY KEY
   (
     [Id] ASC
   )

I am using Entity Framework 4.x with POCO entities.

The Entity Framework code does not write any data to the database, it is simply there to read data created by another service. What I would like to do is have one entity represent BOTH of these tables if possible. The FinancialItem and FinancialItemHistory tables have the same structure. When a FinancialItem gets paid off, the record moves from the FinancialItem table to the FinancialItemHistory table (which keeps the same Id). Is there a way in Entity Framework to conditionally pull in the FinancialItemHistory records if I am including paid off items? Should I create a View in the database that essentially does this:

SELECT Id, TranId, Installment, Amount, 0 IsHistorical
FROM FinancialItem
UNION ALL
SELECT Id, TranId, Installment, Amount, 1 IsHistorical
FROM FinancialItemHistory

I would like to avoid using a view if possible because more times than not I will simply want to pull the unpaid items that reside in the FinancialItem table. I tried having both entities derive from the same interface (IFinancialItem) and then have Entity Framework query that interface, but it appears that Entity Framework does not support mapping to complex types within the context of an IQueryable.

  • 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-03T01:27:25+00:00Added an answer on June 3, 2026 at 1:27 am

    In entity framework, you do a union all using the Concat method. If you want to union two different types, you need to convert both to a common type first like this:

    var table1 = ...;
    var table1 = ...;
    var unionAll = table1.Select(x => new { x.ID, ... }).Concat(table2.Select(x => new { x.ID, ... }));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following tables CREATE TABLE `files` ( `fileid` int(11) NOT NULL AUTO_INCREMENT,
In SQL Server 2008, I have the following tables: CREATE TABLE samples (SampleID int,
I have a table defined by the following SQL: CREATE TABLE test ( id
I have the following tables in SQL Server 2005 ReceiptPoint: ID (PK), Name GasIndexLocation:
i have the following tables in sql server: photoalbumsTable: album_ID album_caption albumtagmap id album_id
I have the following tables: CREATE TABLE title ( booktitle VARCHAR( 60 ), title_id
I have two tables in a SQL Server 2008 database in my company. The
I have a database with a few tables running on SQL Server 2008, and
We have a process updating the database which uses the following SQL IF NOT
I have the following tables, with these keys in my database: bookings session_id sessions

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.