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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:46:48+00:00 2026-06-14T18:46:48+00:00

I am new to Entity Framework and I am stuck with the following. I

  • 0

I am new to Entity Framework and I am stuck with the following.

I have an existing database which I have imported into an EDMX model.

Some of my Entities share the same concept of “owner”.

Each entity have a custom name for the “owner”. Sometimes it is named “author”, sometimes “owner”, sometimes in French “auteur”.

So I have implemented a simple Interface and created partial classes so my Entities could all share the same named concept of “owner”.

public interface IAPIResource
{
    int owner { get; }
}

And my partial class for the entity BlogPost

public partial class BlogPost : IAPIResource
{
    public int owner { get { return auteur; } }
}

Now I want to use it in LINQToEntities query but LINQ tells me that’s not possible because IAPIResource is not an entity type !

public List<T> GetFilteredEntities<T>(int owner, IQueryable<T> entities, MyDBContext db)
{
    return entities.Where(e => ((IAPIResource)e).owner == owner).ToList();
}

I have tried with Reflection (.GetType and .GetProperty and .GetValue) but LINQ does not support that either.

I have tried with POCOs as well, but no much luck.

And I don’t want to modify my DB model with abstract entities and so on.

Does anyone have a simple solution without diving into LINQ Expression ?

NB : the real query is much more complex, that’s why I am not willing to use Expression.

Thank you.

  • 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-14T18:46:50+00:00Added an answer on June 14, 2026 at 6:46 pm

    Entity Framework does not support an explicit cast to IAPIResource, but you don’t need it, you should be able to just do

    public List<T> GetFilteredEntities<T>(int owner, IQueryable<T> entities, MyDBContext db)
        where T : class, IAPIResource
    {
        return entities.Where(e => e.owner == owner).ToList();
    }
    

    However, this does require that you map your owner property in the implementing classes. You currently have

    public int owner { get { return auteur; } }
    

    but that won’t work, because Entity Framework won’t see that owner and auteur are the same property. You do need to change this slightly; my personal preference would be to turn this around: make auteur a wrapper property for owner instead of the other way around. That way, you can continue using auteur in your code, and owner in queries.

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

Sidebar

Related Questions

When adding a new Entity Framework object to a database, how could one have
I'm new to Entity Framework and am using Database First. I have inherited a
I have created a new application using Entity Framework 4.3 database migrations. The migrations
I just downloaded and installed the brand new Entity Framework 5.0 beta 2 which
Being new to the Entity Framework, I'm really rather stuck on how to proceed
I am new to LINQ and Entity Framework and I am stuck on a
I'm starting a new application that must use an existing database that use some
I have a problem in Entity-Framework, using Code-First, that I couldn't solve. Having entities
I configured a new Play Framework application to connect to an existing Sybase database,
I heard about the new entity framework for .net, and decided to modify my

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.