Exemplo n.º 1
0
        static void Main(string[] args)
        {
            using (var db = new PersonDBContext())
            {
                // Create and save a new Blog
                Console.Write("Enter a name for a new person: ");
                var name = Console.ReadLine();

                var primAddr = new PrimaryAddress {
                    streetAddress = "scrubROad", countryRegion = "aarhus amt", zipCode = 8000, cityName = "aarhus"
                };
                db.primaryAddress.Add(primAddr);
                db.SaveChanges();

                var altAddr = new AlternativeAddress {
                    streetAddress = "kkROad", countryRegion = "randers amt", zipCode = 8600, cityName = "randers"
                };
                db.alternativeAddress.Add(altAddr);
                db.SaveChanges();


                var my_email = new Email {
                    email = "*****@*****.**"
                };
                db.emailAddress.Add(my_email);
                db.SaveChanges();

                var primConInf = new PrimaryContactInfo {
                    phoneNumber = 11223344, company = "telenor"
                };
                db.primaryContactInfo.Add(primConInf);
                db.SaveChanges();



                var person = new Person_Class {
                    fullName = name, type = "Hobo", StateRegisterAddress = "rrr"
                };
                db.persons.Add(person);
                db.primaryAddress.Add(primAddr);
                db.alternativeAddress.Add(altAddr);
                db.emailAddress.Add(my_email);
                db.primaryContactInfo.Add(primConInf);
                db.SaveChanges();


                // Display all Blogs from the database
                var query = from b in db.persons
                            orderby b.fullName
                            select b;

                Console.WriteLine("All persons in the database:");
                foreach (var item in query)
                {
                    Console.WriteLine(item.fullName);
                }
            }
        }
Exemplo n.º 2
0
        public void StartDatabase(PersonDBContext db)
        {
            City århus = new City {
                cityName = "Århus", zipCode = 8200
            };

            db.city.Add(århus);

            City randers = new City {
                cityName = "Randers", zipCode = 8900
            };

            db.city.Add(randers);

            PersonType Brother = new PersonType {
                pType = "Brother"
            };

            db.pType.Add(Brother);

            PersonType Friend = new PersonType {
                pType = "Friend"
            };

            db.pType.Add(Friend);

            GenericType Home = new GenericType {
                genericType = "Home"
            };

            db.gType.Add(Home);

            GenericType TDCCompany = new GenericType {
                genericType = "TDC"
            };

            db.gType.Add(TDCCompany);

            GenericType PrivatePhone = new GenericType {
                genericType = "Private"
            };

            db.gType.Add(PrivatePhone);

            GenericType Work = new GenericType {
                genericType = "Work"
            };

            db.gType.Add(Work);

            GenericType OisterCompany = new GenericType {
                genericType = "Oister"
            };

            db.gType.Add(OisterCompany);

            GenericType WorkPhone = new GenericType {
                genericType = "Work"
            };

            db.gType.Add(WorkPhone);

            // Add Person "Jens"
            Address JensAddress = new Address {
                streetAddress = "Randersvej 27b", countryRegion = "Århus amt", addressType = Home, cityAtAddress = århus
            };

            db.address.Add(JensAddress);

            ContactInfo JensPrivatePhone = new ContactInfo {
                phoneNumber = 11223344, phonyType = PrivatePhone, phoneCompany = TDCCompany
            };

            db.contactInfo.Add(JensPrivatePhone);

            Email JensEmail = new Email {
                email = "*****@*****.**"
            };

            db.emailAddress.Add(JensEmail);

            Note JensNote = new Note {
                note = "Jens is my dude"
            };

            Person_Class Jens = new Person_Class {
                fullName = "Jens Petersen", personType = Brother
            };

            Jens.Address.Add(JensAddress);
            Jens.ContactInfo.Add(JensPrivatePhone);
            Jens.EmailAddress.Add(JensEmail);
            //Jens.note
            db.persons.Add(Jens);

            // Add Person "Karl"
            Address KarlAddress = new Address {
                streetAddress = "Sunset Boulevard 33", countryRegion = "Østjylland", addressType = Work, cityAtAddress = randers
            };

            db.address.Add(JensAddress);

            ContactInfo KarlWorkPhone = new ContactInfo {
                phoneNumber = 55667788, phonyType = WorkPhone, phoneCompany = OisterCompany
            };

            db.contactInfo.Add(KarlWorkPhone);

            ContactInfo KarlPrivatePhone = new ContactInfo {
                phoneNumber = 22222222, phonyType = PrivatePhone, phoneCompany = TDCCompany
            };

            db.contactInfo.Add(KarlPrivatePhone);

            Email KarlEmail = new Email {
                email = "*****@*****.**"
            };

            db.emailAddress.Add(KarlEmail);

            Person_Class Karl = new Person_Class {
                fullName = "Karl Sørensen", personType = Friend
            };


            Karl.Address.Add(KarlAddress);
            Karl.ContactInfo.Add(KarlWorkPhone);
            Karl.ContactInfo.Add(KarlPrivatePhone);
            Karl.EmailAddress.Add(KarlEmail);
            db.persons.Add(Karl);
            db.SaveChanges();
        }