public Form_Test_EFE()
        {
            InitializeComponent();
            var connection = Effort.DbConnectionFactory.CreateTransient();

            // CLEAN
 
            // 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 = 34 });
                context.BulkSaveChanges();
            }


            using (var context = new EntityContext2(connection))
            {
                context.EntitySimples.Add(new EntitySimple { ColumnInt = 1 });
                context.EntitySimples.Add(new EntitySimple { ColumnInt = 22 });
                context.EntitySimples.Add(new EntitySimple { ColumnInt = 3 });
                context.BulkSaveChanges();
            }


            var connection2 = Effort.DbConnectionFactory.CreateTransient();
            using (var context = new EntityContext3(connection2))
            {
                context.Database.CreateIfNotExists();
                context.TestEFs.Add(new TestEF { ColumnInt = 1, B = Byte.MaxValue , binary = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 } });
                context.TestEFs.Add(new TestEF { ColumnInt = 22 });
                context.TestEFs.Add(new TestEF { ColumnInt = 3 });
                context.BulkSaveChanges();
            }
            // TEST
            using (var context = new EntityContext(connection))
            {
                var list = context.EntitySimples.ToList();
            }
            using (var context = new EntityContext2(connection))
            {
                var list = context.EntitySimples.ToList();
            }
            using (var context = new EntityContext3(connection2))
            {
                var list = context.TestEFs.Where(x => x.B == Byte.MaxValue).ToList();
                list.ForEach(x => x.B = 133);
                context.BulkUpdate(list);
            }

            using (var context = new EntityContext3(connection2))
            {
                var list = context.TestEFs.Where(x => x.B == 133).ToList();
 
            }

            List<TestEF> listTracking = new List<TestEF>();
            using (var context = new EntityContext3(connection2))
            {
                listTracking = context.TestEFs.ToList();
                listTracking.ForEach(x =>
                {
                    x.B = 122;
                    x.binary = new byte[] {0x20, 0x20, 0x20, 0x20, 0x20};
                });

                listTracking.Add(new TestEF() { B = 122 , binary = new byte[] {  0x20, 0x20, 0x20, 0x20 }, ColumnInt =  555});

                context.BulkMerge(listTracking);

                var list = context.TestEFs.ToList();
                list.ForEach(x =>
                {
                    x.B = 123;
                    x.binary = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20 };
                });

                context.TestEFs.Remove(list.ElementAt(0));
                context.TestEFs.Remove(list.ElementAt(1));
                context.BulkSaveChanges();
            } 

            if (listTracking.Where(x => x.B == 123).ToList().Count !=3)
            {
                throw new Exception("ERROER");
            }

            using (var context = new EntityContext3(connection2))
            {
                var list = context.TestEFs.ToList();
                list.ForEach(x =>
                {
                    x.B = 125;
                    x.binary = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20 };
                });

                context.TestEFs.Remove(list.ElementAt(0)); 
                context.BulkSaveChanges(false);
            }
            if (listTracking.Where(x => x.B == 125).ToList().Count != 3)
            {
                throw new Exception("ERROER");
            }

            using (var context = new EntityContext3(connection2))
            {
                var list = context.TestEFs.Where(x => x.B == 123).ToList();
                var testa = context.TestEFs.Where(x => x.binary == new byte[] {0x20, 0x20, 0x20, 0x20, 0x20}).ToList();

                context.BulkDelete(list);
            }


            using (var context = new EntityContext3(connection2))
            {
                var list = context.TestEFs.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
                }
            }
        }