示例#1
0
        public static string AddNewAddressToEmployee(SoftUniContext context)
        {
            var newAddress = new Address
            {
                AddressText = "Vitoshka 15",
                TownId      = 4
            };

            var nakov = context.Employees.FirstOrDefault(x => x.LastName == "Nakov");

            nakov.Address = newAddress;

            context.Add(newAddress);
            context.Update(nakov);
            context.SaveChanges();

            var employeesAddresses = context
                                     .Employees
                                     .OrderByDescending(x => x.AddressId)
                                     .Take(10)
                                     .Select(e => e.Address.AddressText)
                                     .ToList();

            var sb = new StringBuilder();

            foreach (var address in employeesAddresses)
            {
                sb.AppendLine(address);
            }

            var result = sb.ToString().Trim();

            return(result);
        }