Go Premium for a chance to win a PS4. Enter to Win


How To Add Multiple Family Members

Posted on 2015-01-20
Medium Priority
Last Modified: 2015-02-02
I need a web form that will allow the insert of  family information and then Family Members information. The form needs to collect several family members for a multiple child insert. For example the family "Jones" has members named "Tom", "Felix", "Alicia", "Constance", and "Philip". These all need to be inserted in a single transaction. I have been trying to figure out how to use MVC 5 and Entityframework, and I have tried to figure out how to use Webforms. It seems I need to store the names in a list of some kind and then using "save changes()" insert them into the database tables shown in a picture below. I have looked a several tutorials, but it seems that no one has an need to demonstrate how to achieve this in one. I can't figure out which technology EF or Webforms is the easiest and/or the best way to go, but I am frustrated. Can I get some help with this seemingly straight forward problem?

A set of parent/child tables.
Question by:wdarnellg
  • 6
  • 2
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40561154
So are you asking us to do the work for you, or did you have a specific question that is troubling you? Perhaps if you post the code you tried and any error messages or incorrect behavior you observe?
LVL 64

Expert Comment

by:Fernando Soto
ID: 40561173
Hi wdarnellg;

To your statement, "I have been trying to figure out how to use MVC 5 and Entity Framework", On the Microsoft ASP.NET MVC web site you will find many learning resources, here is a 10 part tutorial on what you wish to do, Creating an Entity Framework Data Model for an ASP.NET MVC Application (1 of 10), and when you have gone through the 10 tutorials you can ask some questions on what you may still not understand. If you have any specific questions please ask.

Author Comment

ID: 40561274
I apologize for being so vague.
I just want help in understanding how to combine the create views or forms of the families and individuals to make a single form that will insert both the Family then the Individual records. The child portion of the form may or may not have more than one or two records to be added. Some families may add up to 6 or 7 family members.
I honestly don't wish to have anyone really do the project for me. There is still validation and some business logic to add to this even though It is an input only app. I would just like to see a working example of creating a new "parent" record, and then adding multiple 'child' records to the transaction on a single form, wizard, or however something like this can work best.

The mvc Create Code I am looking at:

        public ActionResult Create([Bind(Include = "Id,FamilyName,PhoneNumber,Email,Address1,Address2,City,State,ZipCode,MyPreferedSite,FamilyIncome,RowVersion")] Families families) 
            if (ModelState.IsValid)
// I am guessing that some kind of way to get a family Id would go here
// I am guessing that some kind of Individuals collections or lists would go here with the new family id.
                return RedirectToAction("Index");

            return View(families);

Open in new window

But how to create the Family ID and HOW to create the list of Individuals.

I would love a tutorial, or some kind of guide that will address this kind of scenario kind of head on, if one exists.

I did a small application similar to this using Lightswitch. It made this kind of parent child collection/insertion quite easy... perhaps too easy as it all worked behind the scenes.. Lightswitch doesn't play very well with non-Microsoft products like iPads etc... so my project became impractical for the group I have to work with.
I am not a professional programmer, so I am trying my best here.

Thanks for the patience.  :-)
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 40561688
Thanks Fernando. I did the Contoso University tutorial and it is very good and helpful, except that it doesn't address the kind of UI I am talking about. It shows how to create related records of course, but it does it one entity at a time, and different insert operations. The example I seek will show how to create a "parent" and "multiple children" in a single transaction.
:-) It seems ironic to me that in a world of parent-children records, that I struggle with records of actual parents and children.
Per your suggestion, I am reviewing the database first version of Contoso University: http://www.asp.net/mvc/overview/getting-started/database-first-development/setting-up-database 
I am probably missed something.
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40561820
To confirm, what technologies are you using? It sounds like you've now decided on MVC and Entity Framework. Is that correct?

Author Comment

ID: 40564183
Hi kaufmed.
I think for the moment anyway, I will pursue trying to understand if and how mvc/ef will work. However, (and please forgive me if I continue to seem vague), if there is a webforms example to look at, I am very open to looking at it or them if more than one.

Accepted Solution

wdarnellg earned 0 total points
ID: 40575092
I found a course on Pluralsight that addresses parent child records using EF. It also brings in Knockout, ajax, and mvc.
This has me moving in the right direction.
Thanks for trying.

Author Comment

ID: 40577880
I thought I would add one last comment to this question. As stated in my previous post, the course found at http://www.pluralsight.com/courses/parent-child-data-ef-mvc-knockout-ajax is pretty much exactly what I was seeking in terms of creating parent with multiple children records in a single transaction. I must say that this is NOT an easy task. If you are inexperienced at this as I am, the course is a wonderful step by step. But even the course instructor states his disappointment in the lack of documentation and tutorials on what seems like a pretty basic need for collecting data. I am finding the learning curve worth the time and I encourage anyone this may help to hang in there.
I am sure there are other solutions, maybe even easier ones, but this one is at least findable and well demonstrated.
Good Luck,

Author Closing Comment

ID: 40583546
I couldn't seem to ask the right question to get any guidance. I wanted ANY help possible using ANY technology that would get me a simple input web app. I guess my question was just too vague. I found some help with the Pluralsight.com course by Adam Churvis.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question