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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:35:34+00:00 2026-05-18T21:35:34+00:00

I will compare 2 scenarios to add Rsvp rows. Which one do you prefer

  • 0

alt text

I will compare 2 scenarios to add Rsvp rows. Which one do you prefer in production?


METHOD 1: Adding a new Rsvp object to datacontext’s Rsvp collection

Rsvp r = new Rsvp();
r.AttendeeName = "xport";

r.DinnerId = 1;//there will be an exception if it is set to a Dinnner object that does not exist.

entities.Rsvps.AddObject(r);

entities.SaveChanges();

We will get an exception if we attempt to set DinnerId to a Dinner object that does not exist. This behavior is consistent and straightforward.


METHOD 2: Adding a new Rsvp object to a Dinner object’s Rsvps properties

Rsvp r = new Rsvp();
r.AttendeeName = "xport";

r.DinnerId = 10000;//this Dinner does not exist!

Dinner d = entities.Dinners.First(x => x.DinnerId == 1);

d.Rsvps.Add(r);

entities.SaveChanges(); 

The foreign key property DinnerId of a Rsvp object can be set to any number. When this Rsvp object is added to a Dinner object’s Rsvps collection, the DinnerId will be overriden silently. Example above shows DinnerId is set to 10000 which is an Id of an Dinner object that does not exist. Is it an unavoidable behavior?

  • 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-18T21:35:34+00:00Added an answer on May 18, 2026 at 9:35 pm

    Definetely method 2.

    Why? Because a Rsvp cannot exist without a Dinner. In this relationship, Dinner is the parent – and if we were to create a Repository, we would create a DinnerRepository (as Dinner is the “aggregate root” in DDD terms)

    In regards to your note – yes, this is avoidable behaviour – what you should do is don’t expose the foreign keys on the model. This is an option available when you create/update your model.

    This way, the relationships must be created/modified via the entity:

    Rsvp r = new Rsvp();
    r.AttendeeName = "xport";
    r.DinnerId = 10000; // this throws a compiler error. good! we do not want people tinkering with FK's.
    Dinner d = entities.Dinners.First(x => x.DinnerId == 1);
    d.Rsvps.Add(r); // this is the correct way to add a RSVP
    entities.SaveChanges(); 
    

    In other words – the only way to create/modify a Rsvp is via a Dinner – and the FK property cannot be modified.

    Which makes sense.

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

Sidebar

Related Questions

So I have this method which will take an ArrayList of Integers, I compare
Is there a Linux command-line app which will compare two binary files and exit
I have written a code for finding intersection of two multimap which will compare
In this example in xaxis will compare the days... $.plot($(#placeholder), data, { yaxis: {},
Okay, here's my short question: I know that === and !== operators will compare
I am trying to compare two files. I will list the two file content:
So I've heard that if I compare 2 strings with == then I will
is there anything built-in in Django templates that will allow me to compare two
Given the UINavigationController delegate methods: -(void)navigationController:(UINavigationController*)navigationController (will/did)ShowViewController:(UIViewController*)viewController animated:(BOOL)animated How do you tell or compare
The process of creating a new build and releasing it to production is a

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.