Exemplo n.º 1
0
 public static void InsertPerson()
 {
     using (var context = new EFDContext())
     {
         context.People.Add(new Person() {FirstName = "Bob", LastName = "Rogden"});
         context.SaveChanges();
     }
 }
Exemplo n.º 2
0
 public static void UpdatePerson()
 {
     using (var context = new EFDContext())
     {
         var per = context.People.FirstOrDefault();
         per.LastName = DateTime.Now.ToString();
         context.SaveChanges();
     }
 }
        public static void GetParentObjectOnlyByWhere()
        {
            using (var context = new EFDContext())
            {
                var people = context.People.Where((p => p.LastName == "Rogden")).Select(x=>new {FirstName= x.FirstName}).ToList();
                var actualpeople = context.People.Where((p => p.LastName == "Rogden")).ToList();

            }
        }
        //get a parent object with Find. This object should have a child object property that we don't want retrieved
        //I don't see anything in sql profiler retrieving anything about the Address collection
        public static void GetParentObjectOnlyByFind()
        {
            using (var context = new EFDContext())
            {

                var people = context.People.Find(7);

            }
        }
Exemplo n.º 5
0
 public static void GetPeople()
 {
     using (var context = new EFDContext())
     {
         var people = context.People.ToList();
         foreach (var person in people)
         {
             Console.WriteLine(person.FirstName + " " + person.LastName);
         }
     }
 }
Exemplo n.º 6
0
 //create new parent object and new children objects
 public static void CreateObjectGraph()
 {
     using (var context = new EFDContext())
     {
         var p = new Person() {FirstName = "Bob", LastName = "Rogden"};
         p.Addresses.Add((new Address(){Street = "main street"}));
         //do you have to specify the person id or Person peroperty on the address or will it just work?
         //COOL, it just works
         context.People.Add(p);
         context.SaveChanges();
     }
 }