예제 #1
0
파일: Program.cs 프로젝트: jw56578/EFTest
 public static void InsertPerson()
 {
     using (var context = new EFDContext())
     {
         context.People.Add(new Person() {FirstName = "Bob", LastName = "Rogden"});
         context.SaveChanges();
     }
 }
예제 #2
0
파일: Program.cs 프로젝트: jw56578/EFTest
 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);

            }
        }
예제 #5
0
파일: Program.cs 프로젝트: jw56578/EFTest
 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);
         }
     }
 }
예제 #6
0
파일: Program.cs 프로젝트: jw56578/EFTest
 //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();
     }
 }