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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:55:40+00:00 2026-05-14T15:55:40+00:00

Im using the above technologies and have ran into what I presume is a

  • 0

Im using the above technologies and have ran into what I presume is a design issue I have made.

I have an Artwork table in my DB and have been able to add art (I now think of these as Digital Products) to a shopping cart + CartLine table fine. The system I have that adds art to galleries and user accounts etc works fine.

Now the client wants to sell T-shirts, Mugs and Pens etc, ‘HardwareProducts’ so I have created a ‘HardwareProducts’ table.

Now I have two different product types in two tables. I use GUID’s as the PK’s in both the HardwareProducts table and Artwork table. When a customer adds an item to their cart I store the GUID in the ProductID column in the CartItems table.

The issue is the database will not know which table to reference when I bring the LineItem object up through my ORM to the front end.

In OOP I can see how you would have a base class of Product, and then a DigitalProduct class and HardwareProduct class drived from it, but how do you model this in SQL Server and the Entity Framework please, or is there another way?

EDIT:

This is what I have in a test app at the moment thanks to the below comments. The trick that did it for me was utilising the ORM simular to what Stephane pointed out. It lead me to this excellent article.

alt text http://img411.imageshack.us/img411/3568/32654541.jpg

Allows:

int prodCount = _entities.Product.OfType<ArtWork>().Count();
IEnumerable<LineItem> lineItem = _entities.LineItem.Include("Product");
int artWorkCount = lineItem.Select(p => p.Product).OfType<ArtWork>().Count();

ArtWork prod = new ArtWork();
            prod.Price = 2;
            prod.ProductName = "atlast";
            prod.Downloads = 3;
            prod.GalleryID = 1;
            _entities.AddToProduct(prod);
            _entities.SaveChanges();

I am about to integrate it into my main solution and will let you know if I have anymore findings, but I think all is looking good. NB It appears the Type column which was mentioned, was not actually needed in the end which was a nice surprise thanks to the clean solution the ORM provided. Thx all

  • 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-05-14T15:55:40+00:00Added an answer on May 14, 2026 at 3:55 pm

    This is a very cool scenario to show off one feature of EntityFramework!

    You could have a single table product, and a type column that defines the type of product.
    Then in your Entity Data Model you define a base entity Product, and you create 2 derived entities HardwareProduct and ArtProduct. You can add a Condition on the Mapping for your child Entity like so :

    EDIT : You should read When ProductTypeID = 1, but I’m lazy to redo the screenshot now 😉

    inherited entity and condition

    See the “When ProductTypeID = 1 “

    There 🙂

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

Sidebar

Related Questions

No related questions found

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.