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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:33:22+00:00 2026-06-17T14:33:22+00:00

I have this database Packages (packageID, package_name , …. ) PackageVariant (packageID, variantID) Variant

  • 0

I have this database

Packages (packageID, package_name , .... )
PackageVariant (packageID, variantID)
Variant (variantID, variant_name, .... )
VariantProduct (variantID, productID, quantity)
Product (productID, product_name, .... )

I have modelled it in Entity Framework, I don’t know the multiplicities but they should be based on below:

A Package can have None or Multiple Variants
A Variant can be associated with only One Package (can’t be none or multiple)
One Variant can have One or Multiple Products
Products are associated with None or Multiple Variants

When a Package is deleted, all Variants of that Package must be deleted.
When a Variant is deleted nothing else is needed to be deleted.
When a Product is deleted, all associations with Variants need to be deleted.

If you can provide help with the multiplicities and where the OnDelete:Cascade needs to be set that would be great!

I also need to be able to do this:

var ptx = new MyEntities();
Variant newVariant = new Variant()
{
    setRelevantProperty = value
};
Product selectedProduct = ptx.Products.First(o => o.productID == productID);
newVariant.Products.Add(selectedProduct);
Package packageToAddVariantTo = ptx.Packages.First(o => o.packageID == packageID);
packageToAddVariantTo.Variants.Add(newVariant);
ptx.SaveChanges();

without getting an error due to “There is no Insert, Update set” or anything else that relies on the mappings. So how to correctly map this complex database would be good 🙂

I have read a few posts, books and I can’t seem to find the answer.

Thanks

  • 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-17T14:33:23+00:00Added an answer on June 17, 2026 at 2:33 pm

    Lee O got the answer, I’ll just re post it as an answer rather than a comment for reader clarity:

    I’m not sure of the answer to your question but I would make 1 recommendation, get rid of the PackageVariant table. You only need a table like that when you have a multiple to multiple relationship. Just add a column in the variant table called packageId and make it a foreign key to the package table and not null. This will enforce your rule of 1 package exactly per variant. But none to multiple variants per package.

    Thanks Lee

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

Sidebar

Related Questions

I have this database structure, SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; CREATE TABLE IF NOT EXISTS `announces` (
I have this enormous database : # # Dropping tables # DROP TABLE IF
We have this current database which we need to replace some tables by anther
So I have this game database, where I have several users with fields, id,
I have this old Access database (2000 format) which i want to convert to
I have this field from the database which is: DataType: Numeric (7, 3) So
I have this line: @users = database['users'].find(:all).limit(10) it returns this object: <Mongo::Cursor:0x8759a858 namespace='app-development.users' @selector=:all
In mysql database i have this column called: Name: Date Type: datetime I have
I have this strings saved in my mysql database in format like: /uploads/attachments/18/105/WordPress_3_Cookbook.pdf Now,
I have this code to update my SQL database from data in a textbox,

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.