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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:48:36+00:00 2026-05-19T21:48:36+00:00

I found some questions that looked similar, but not exactly the same so I’ll

  • 0

I found some questions that looked similar, but not exactly the same so I’ll go for it.

I’m using EF to retrieve 2 tables. These tables/entities have no real “is a” relationship. They just happen to have a couple of common fields which I want to expose in a list containing the first N entries of a combination between the two tables. Each row has to have some way of identifying which type it is and which instance it points to.

I have solved the problem, but I guess I was wondering if there was a better way. My solution was to create a ViewModel class:

intenal class EntityAEntityBCombination
{
    public int? EntityAID { get; set; }
    public int? EntityBID { get; set; }
    public string CommonProperty { get; set; }
}

Then I did this:

var results = (
    from a in EntityAList select new EntityAEntityBCombination
        { EntityAID = a.Id, EntityBID = null, CommonProperty = a.CommonProperty }
    ).Concat(
    from b in EntityBList select new EntityAEntityBCombination
        { EntityAID = null, EntitiyBID = b.Id, CommonProperty = b.CommonProperty }
    ).Fetch(N)

It works, but seems dirty. Any suggestions?

  • 1 1 Answer
  • 1 View
  • 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-05-19T21:48:36+00:00Added an answer on May 19, 2026 at 9:48 pm

    Have a look at this, perhaps it doesn’t work straight out of the box, but it should give you an idea:

    public class EntityA : IEntity
    {}
    
    public class EntityB : IEntity
    {}
    
    List<IEntity> results = 
    (from a in EntityAList select a).Cast<IEntity>()
    .Concat(
    (from b in EntityBList select b).Cast<IEntity>()
    )
    .Fetch(N).ToList();
    
    foreach (IEntity entity in results)
    {
     if (entity is EntityA)
      // do something with entity A
    
     if (entity is EntityB)
      // do something with entity B
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've found some similar questions on StackOverflow, but nothing that addresses what I'm looking
I've looked through similar questions but not found the exact working solution I'm after.
I looked around and found other questions that had answers but none of them
Ran into another challenge. I looked through some of the questions that I found
I have some questions regarding the following css that I found: html, body {
I've found some questions here about this topic, but none of the solutions solve
I'm sure this is asked plenty and i've found some questions on here similar
I found some other questions about this, but they didn't work for me :(
I looked at some other questions on SO and its not clear if c
I checked some other similar questions but some of them are old and i'm

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.