Esempio n. 1
0
        public static void Execute()
        {
            // Create BD
            using (var context = new EntityContext())
            {
                My.CreateBD(context);
            }

            // CLEAN
            using (var context = new EntityContext())
            {
                context.EntitySimples.RemoveRange(context.EntitySimples);
                context.EntitySimpleChilds.RemoveRange(context.EntitySimpleChilds);
                context.EntitySimpleLists.RemoveRange(context.EntitySimpleLists);

                context.SaveChanges();
            }

            var entity = new EntitySimple {
                ColumnInt = 0
            };

            // SEED
            using (var context = new EntityContext())
            {
                context.EntitySimples.Add(entity);

                context.SaveChanges();
            }

            entity.EntitySimpleChild = new EntitySimpleChild()
            {
                ColumnInt = 1
            };
            entity.EntitySimpleLists = new List <EntitySimpleList>()
            {
                new EntitySimpleList()
                {
                    ColumnInt = 2
                }, new EntitySimpleList()
                {
                    ColumnInt = 3
                }
            };

            // TEST
            using (var context = new EntityContext())
            {
                context.UpdateGraph(entity, map => map.AssociatedEntity(c => c.EntitySimpleChild).AssociatedCollection(c => c.EntitySimpleLists));
                context.SaveChanges();
            }

            using (var context = new EntityContext())
            {
                var a = context.EntitySimples.ToList();
                var b = context.EntitySimpleChilds.ToList();
                var c = context.EntitySimpleLists.ToList();
            }
        }
Esempio n. 2
0
        public static void Execute()
        {
            // Create BD
            using (var context = new EntityContext())
            {
                My.CreateBD(context);
            }

            // CLEAN
            using (var context = new EntityContext())
            {
                context.EntitySimples.RemoveRange(context.EntitySimples);
                context.EntitySimpleChilds.RemoveRange(context.EntitySimpleChilds);
                context.EntitySimpleLists.RemoveRange(context.EntitySimpleLists);

                context.SaveChanges();
            }

            var entity = new EntitySimple {
                ColumnInt = 0
            };

            // SEED
            using (var context = new EntityContext())
            {
                entity.EntitySimpleChild = new EntitySimpleChild()
                {
                    ColumnInt = 1
                };
                var EntitySimpleLists = new List <EntitySimpleList>()
                {
                    new EntitySimpleList()
                    {
                        ColumnInt = 2
                    }, new EntitySimpleList()
                    {
                        ColumnInt = 3
                    }
                };

                context.EntitySimples.Add(entity);

                context.EntitySimpleLists.AddRange(EntitySimpleLists);
                context.SaveChanges();
            }

            EntitySimpleList entityChildList = null;

            using (var context = new EntityContext())
            {
                entity                   = context.EntitySimples.Include(x => x.EntitySimpleChild).First();
                entityChildList          = context.EntitySimpleLists.First();
                entity.EntitySimpleLists = new List <EntitySimpleList>()
                {
                    entityChildList
                };
            }

            entityChildList.ColumnInt          = 20;
            entityChildList.EntitySimpleList2s = new List <EntitySimpleList2>()
            {
                new EntitySimpleList2()
            };

            // TEST
            using (var context = new EntityContext())
            {
                context.UpdateGraph(entity, map => map.AssociatedEntity(c => entity.EntitySimpleLists).AssociatedCollection(c => c.EntitySimpleLists));
                //context.UpdateGraph(entity.EntitySimpleLists.First(), map => map.AssociatedEntity(c => c.EntitySimpleList2s));
                context.SaveChanges();
            }

            using (var context = new EntityContext())
            {
                var a = context.EntitySimples.ToList();
                var b = context.EntitySimpleChilds.ToList();
                var c = context.EntitySimpleLists.ToList();
            }
        }
Esempio n. 3
0
        public static void Execute()
        {
            // Create BD
            using (var context = new EntityContext())
            {
                My.CreateBD(context);
            }

            // CLEAN
            using (var context = new EntityContext())
            {
                context.EntitySimples.RemoveRange(context.EntitySimples);
                context.EntitySimpleChilds.RemoveRange(context.EntitySimpleChilds);
                context.EntitySimpleLists.RemoveRange(context.EntitySimpleLists);

                context.SaveChanges();
            }

            var entity = new EntitySimple {
                ColumnInt = 0
            };

            // SEED
            using (var context = new EntityContext())
            {
                context.EntitySimples.Add(entity);

                context.SaveChanges();
            }

            entity.EntitySimpleChild = new EntitySimpleChild()
            {
                ColumnInt = 1
            };
            entity.EntitySimpleLists = new List <EntitySimpleList>()
            {
                new EntitySimpleList()
                {
                    ColumnInt = 2
                }, new EntitySimpleList()
                {
                    ColumnInt = 3
                }
            };

            // TEST
            using (var context = new EntityContext())
            {
                //	var node1 = context.UpdateGraph(entity, map => map.OwnedEntity(p => p.EntitySimpleChild, (Expression<Func<IUpdateConfiguration<EntitySimpleChild>, object>>) with =>
                //		with.OwnedCollection(p => p.EntitySimples)));
                //	context.UpdateGraph(entity, map => map.AssociatedEntity(c => c.EntitySimpleChild).AssociatedCollection(c => c.EntitySimpleLists, x => x.B));

                context.UpdateGraph(entity, map => map.AssociatedCollection(c => c.EntitySimpleLists, x => x.B).AssociatedEntity(c => c.EntitySimpleChild));

                //context.UpdateGraph(entity, map => map.AssociatedEntity(c => c.EntitySimpleChild).AssociatedCollection(c => c.EntitySimpleLists));
                //context.UpdateGraph(entity, map => map.OwnedEntity(c => c.EntitySimpleChild).OwnedCollection(c => c.EntitySimpleLists));
                context.SaveChanges();
            }

            entity = new EntitySimple {
                ColumnInt = 101
            };
            using (var context = new EntityContext())
            {
                entity.EntitySimpleChild = new EntitySimpleChild()
                {
                    ColumnInt = 1
                };
                entity.EntitySimpleLists = new List <EntitySimpleList>()
                {
                    new EntitySimpleList()
                    {
                        ColumnInt = 2
                    }, new EntitySimpleList()
                    {
                        ColumnInt = 3
                    }
                };


                context.EntitySimples.Add(entity);

                context.SaveChanges();
            }

            using (var context = new EntityContext())
            {
                var a = context.EntitySimples.ToList();
                var b = context.EntitySimpleChilds.ToList();
                var c = context.EntitySimpleLists.ToList();
            }
        }