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

  • Home
  • SEARCH
  • 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 8631785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:15:55+00:00 2026-06-12T09:15:55+00:00

Using entity framework (with MVC, but I think that’s irrelevant), I’m trying to make

  • 0

Using entity framework (with MVC, but I think that’s irrelevant), I’m trying to make an entity that’s…extensible.

I have a number of classes that users can label as favorites or bookmarks…there’s actually several different objects that utilize this functionality. The way I currently have this implemented in my model is like this (as an example):

public class Favorite
{
   [key]
   public int FavoriteId {get; set;}

   public int? BikeId {get; set;}
   public virtual Bike Bike {get;set;}

   public int? HelmetId {get;set;}
   public virtual Helmet Helmet {get;set;}

   public int? ShoeId {get;set;}
   public virtual Shoe Shoe{get;set;}

   public int UserId {get;set;}
   public virtual User User {get;set;}
}

and the bike, helmet, user, and shoe class all resemble this:

public class Bike
{
   public int BikeId {get;set;}
   ...
   public virtual list<Favorties> Favorites {get;set;}
}

So currently my table looks like this:

Favorites:
|   Id   |  BikeId  |  HelmetId  | ShoeId   | UserId        |
|   1    |    5     |            |          | snowburnt     |
|   2    |    6     |            |          | jonh          |
|   3    |          |     2      |          | snowburnt     |

I would prefer a structure for the favorite object where there is a differentiator column that stores the name of the object being reference as part of a multiple column primary key so that the favorites table looks more like this (I know the user ID isn’t an int):

Favorites:
|   ID    |   Differentiator   |   foreignKeyId    | UserId       |
|    1    |     Bike           |    5              | snowburnt    |
|    2    |     Bike           |    6              | john         |
|    3    |     Helmet         |    2              | snowburnt    |

The primary reason for wanting to do this is so that if I have new objects that I want to integrate into favorites I won’t have to modify the structure of the favorites object.

The hierarchy should be something like:

Bike, helmet, etc have 0 to many favorites

Is this possible in asp.net entity framework? How can I do this? Any good references out there for getting deep into the entity framework?

One note: I’ve seen the posts here, http://weblogs.asp.net/manavi/archive/2010/12/24/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-1-table-per-hierarchy-tph.aspx which would work great…If I had an inheritance situation here (most of the reason I can’t have an inheritance situation is that I have multiple classes or interfaces that require the same relationship: favorites, bookmarks, comments, reviews, etc). It’s very probably that I could/should use interfaces for the favorites (make bike, helmet Favoritables). I haven’t found any notes on how that would end up mapping in the SQL Schema (would there even be a favorites table then?)

  • 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-12T09:15:55+00:00Added an answer on June 12, 2026 at 9:15 am

    If you want to have table with described structure you must use ADO.NET and SQL for that. EF cannot map it. EF is only able to map real relations (referential constraints). Your table has no real relations – it has just data with some special meaning for your application and EF currently doesn’t support data driven mapping except some very simple scenarios like mentioned table per hierarchy inheritance. If you want to use EF you must live with the table structure you have at the moment.

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

Sidebar

Related Questions

I am using Entity Framework with asp.net mvc, but I don't think mvc plays
I have an ASP.NET MVC 3 (using Entity Framework 4.2) application that uses transactions
I have an MVC 3 project that I am working on using Entity Framework
Using ASP MVC and Entity Framework. In the view, you have a page declaration
When using ASP.NET MVC plus Entity Framework, and trying to implement a generic repository
I am using MVC (C#) and the Entity Framework. I have a sql server
I am using the asp.net mvc with the Entity Framework. I have a list
Whats best way for that on MVC 4 with Entity Framework. Example: We have
I have an MVC 3 web application using Entity Framework to access the projects
I have a ASP.NET MVC 3 application, using Entity Framework 4 to handle Data

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.