public Form_Request_EffortExtra()
        {
            InitializeComponent();

            var data = new ObjectData();

            var entitySimples = data.Table <EntitySimple>();

            entitySimples.Add(new EntitySimple {
                ID = 1, ColumnInt = -1
            });
            entitySimples.Add(new EntitySimple {
                ID = 2, ColumnInt = -2
            });

            var objectDataLoader = new ObjectDataLoader(data);

            var connection = DbConnectionFactory.CreateTransient(objectDataLoader);

            // SEED
            using (var context = new EntityContext(connection))
            {
                context.Database.CreateIfNotExists();

                context.EntitySimples.Add(new EntitySimple {
                    ColumnInt = 1
                });
                context.EntitySimples.Add(new EntitySimple {
                    ColumnInt = 2
                });
                context.EntitySimples.Add(new EntitySimple {
                    ColumnInt = 3
                });
                context.SaveChanges();
                var entity = context.EntitySimples.Where(x => x.ColumnInt == 2).First();

                context.EntitySimples.Remove(entity);

                context.EntitySimples.Add(new EntitySimple {
                    ColumnInt = 4
                });

                context.SaveChanges();

                var entity2 = context.EntitySimples.Where(x => x.ColumnInt == 4).First();


                connection.CreateRestorePoint();


                context.EntitySimples.Add(new EntitySimple {
                    ColumnInt = 5
                });
                context.SaveChanges();

                var list2 = context.EntitySimples.ToList();
                connection.RollbackToRestorePoint(context);

                context.EntitySimples.Add(new EntitySimple {
                    ColumnInt = 9
                });
                context.SaveChanges();
                var list3 = context.EntitySimples.ToList();

                var entity3 = context.EntitySimples.Where(x => x.ColumnInt == 4).First();
            }

            // TEST
            using (var context = new EntityContext(connection))
            {
                var list = context.EntitySimples.ToList();
            }
        }
예제 #2
0
        public Form_General_Mik()
        {
            InitializeComponent();


            {
                var data = new ObjectData();

                // with [Table("TableTest")] on EntitySimple ==> not insert because not EntitySimples.
                // but without  [Table("TableTest")] on EntitySimple ==> insert because name is EntitySimples.
                data.Table <EntitySimple>("EntitySimples").Add(new EntitySimple {
                    ID = 1, ColumnInt = 55
                });
                data.Table <EntitySimple>("EntitySimples").Add(new EntitySimple {
                    ID = 2, ColumnInt = 55
                });
                data.Table <EntitySimple>("EntitySimples").Add(new EntitySimple {
                    ID = 3, ColumnInt = 55
                });


                data.Table <EntitySimple>().Add(new EntitySimple {
                    ID = 1, ColumnInt = 55
                });
                data.Table <EntitySimple>().Add(new EntitySimple {
                    ID = 2, ColumnInt = 55
                });
                data.Table <EntitySimple>().Add(new EntitySimple {
                    ID = 3, ColumnInt = 55
                });


                //data.Table<EntitySimple>("EntitySimples").Add(new EntitySimple { ColumnInt = 55 });
                //data.Table<EntitySimple>("EntitySimples").Add(new EntitySimple { ColumnInt = 55 });
                //data.Table<EntitySimple>("EntitySimples").Add(new EntitySimple { ColumnInt = 55 });
                data.Table <EntitySimple2>().Add(new EntitySimple2 {
                    ColumnInt = 55
                });
                data.Table <Entity>().Add(new Entity {
                    ColumnInt = 55
                });


                data.Table <Customer>().Add(new Customer {
                    ColumnInt = 55
                });
                //     data.Table<Entity>().Add(new Entity { ColumnInt = 55 });
                var dataLoader = new ObjectDataLoader(data);

                var connection = Effort.DbConnectionFactory.CreateTransient(dataLoader);

                //  var connection = Effort.DbConnectionFactory.CreateTransient();


                // SEED
                using (var context = new EntityContext(connection))
                {
                    context.EntitySimples.Add(new EntitySimple {
                        ColumnInt = 1
                    });
                    context.EntitySimples.Add(new EntitySimple {
                        ColumnInt = 2
                    });
                    context.EntitySimples.Add(new EntitySimple {
                        ColumnInt = 3
                    });
                    context.EntitySimples2.Add(new EntitySimple2 {
                        ColumnInt = 1
                    });
                    context.EntitySimples2.Add(new EntitySimple2 {
                        ColumnInt = 2
                    });
                    context.EntitySimples2.Add(new EntitySimple2 {
                        ColumnInt = 3
                    });
                    context.Entities.Add(new Entity {
                        ColumnInt = 1
                    });
                    context.Entities.Add(new Entity {
                        ColumnInt = 2
                    });
                    context.Entities.Add(new Entity {
                        ColumnInt = 3
                    });
                    context.Customers.Add(new Customer()
                    {
                        ColumnInt = 1
                    });
                    context.Customers.Add(new Customer {
                        ColumnInt = 2
                    });
                    context.Customers.Add(new Customer {
                        ColumnInt = 3
                    });
                    context.SaveChanges();
                }

                // TEST
                using (var context = new EntityContext(connection))
                {
                    var list1 = context.EntitySimples.ToList();  // 6
                    var list2 = context.EntitySimples2.ToList(); //4
                    var list3 = context.Entities.ToList();       // need 4
                    var list4 = context.Customers.ToList();      // need 4
                }
            }
        }