Beispiel #1
0
        public async Task <T> InsertAsync(
            T entity)
        {
            entity.Created = DateTimeOffset.Now;
            var result = await Db.Set <T>().AddAsync(entity);

            _ = Db.SaveChanges();
            return(result.Entity);
        }
Beispiel #2
0
        public void Run()
        {
            _logger.LogInformation($"This is a console application for {_config.Title}");

            var serviceCollection = new ServiceCollection();

            using (MeasureContext context = new MeasureContext(null))
            {
                PhoneNumberType fax = new PhoneNumberType {
                    Name = "Fax"
                };
                PhoneNumberType work = new PhoneNumberType {
                    Name = "Work"
                };

                Client parent = new Client {
                    CompanyName = "Home Depot", Address = new Address(), BillingAddress = new Address()
                };
                Client store = new Client {
                    CompanyName = "Store 127", Address = new Address(), BillingAddress = new Address(), Parent = parent
                };
                context.Clients.Add(store);
                store.PhoneNumbers.Add(new PhoneNumberClient {
                    Number = "555.666.7777", PhoneNumberType = fax
                });
                store.PhoneNumbers.Add(new PhoneNumberClient {
                    Number = "555.666.7778", PhoneNumberType = fax
                });
                store.PhoneNumbers.Add(new PhoneNumberClient {
                    Number = "555.666.8777", PhoneNumberType = work
                });
                store.PhoneNumbers.Add(new PhoneNumberClient {
                    Number = "555.666.8778", PhoneNumberType = work
                });
                parent.PhoneNumbers.Add(new PhoneNumberClient {
                    Number = "555.667.7777", PhoneNumberType = fax
                });
                parent.PhoneNumbers.Add(new PhoneNumberClient {
                    Number = "555.667.7778", PhoneNumberType = fax
                });
                parent.PhoneNumbers.Add(new PhoneNumberClient {
                    Number = "555.667.8777", PhoneNumberType = work
                });
                parent.PhoneNumbers.Add(new PhoneNumberClient {
                    Number = "555.667.8778", PhoneNumberType = work
                });
                context.Clients.Add(parent);
                int           count     = context.SaveChanges();
                List <Client> customers = context.Clients.ToList();
            }
        }