예제 #1
0
        static void Main(string[] args)
        {
            var optionBuliderWrite = new DbContextOptionsBuilder <PersonContext>();

            optionBuliderWrite.UseSqlServer(

                @"Server=(localdb)\mssqllocaldb;initial catalog=CQRSWrite;integrated security=true;"
                );


            var optionBuliderRead = new DbContextOptionsBuilder <PersonContext>();

            optionBuliderRead.UseSqlServer(

                @"Server=(localdb)\mssqllocaldb;initial catalog=CQRSRead;integrated security=true;"
                );

            var contextWrite = new PersonContext(optionBuliderWrite.Options);
            var contextRead  = new PersonContext(optionBuliderRead.Options);



            //context.Database.EnsureCreated();


            var ReadRep  = new PersonReadRepository(contextRead.Database.GetDbConnection().ConnectionString);
            var WriteRep = new PersonWriteRepository(contextWrite);



            //    WriteRep.Add(new Entities.Person {

            //FirstName="Reza",
            //LastName="Akbari"


            //    });

            var list = ReadRep.GetAll();

            foreach (var item in list)
            {
                Console.WriteLine(string.Format($"Name{item.FirstName}" + " " + $"Name{item.LastName}"));
            }
            Console.ReadKey();
        }
예제 #2
0
        static void Main(string[] args)
        {
            var OptionBuilderWrite = new DbContextOptionsBuilder <PersonContext>();

            OptionBuilderWrite.UseSqlServer("Server=.;Database=CQRSDBWrite;User Id = sa;Password = ABCabc123456;");

            var OptionBuilderRead = new DbContextOptionsBuilder <PersonContext>();

            OptionBuilderRead.UseSqlServer("Server=.;Database=CQRSReadDB;User Id = sa;Password = ABCabc123456;");

            var ctxWrite = new PersonContext(OptionBuilderWrite.Options);
            var ctxRead  = new PersonContext(OptionBuilderRead.Options);

            ctxWrite.Database.EnsureDeleted();
            ctxRead.Database.EnsureDeleted();

            ctxWrite.Database.EnsureCreated();
            ctxRead.Database.EnsureCreated();

            var ReadRepo  = new PersonReadRepository(ctxRead);
            var WriteRepo = new PersonWriteRepository(ctxWrite);

            WriteRepo.Add(new _01.Entities.Person
            {
                FirstName = "Hassan",
                LastName  = "Asil"
            });

            var list = ReadRepo.GetAll();

            foreach (var item in list)
            {
                Console.WriteLine($"FirstName:{ item.FirstName} lastName:{ item.LastName}");
            }

            Console.ReadLine();
        }