public async Task <Address> GetByIdAsync(int Id)
 {
     using (var context = new AdventureWorks2017Context())
     {
         return(await context.Person.Where(p => p.BusinessEntityId == Id)
                .Join(context.BusinessEntityAddress, p => p.BusinessEntityId, b => b.BusinessEntityId, (p, b) => b)
                .Join(context.Address, b => b.AddressId, a => a.AddressId, (b, a) => a)
                .FirstOrDefaultAsync());
     }
 }
 // Returns Employees where their names contain the given string
 public async Task <Employee> GetByIdAsync(int id)
 {
     using (var context = new AdventureWorks2017Context())
     {
         try
         {
             return(await context.Employee.FirstOrDefaultAsync(e => e.BusinessEntityId == id));
         }
         catch
         {
             return(null);
         }
     }
 }
 public async Task <Person> GetByIdAsync(int id)
 {
     using (var context = new AdventureWorks2017Context())
     {
         try
         {
             return(await context.Person.Where(p => p.BusinessEntityId == id).FirstOrDefaultAsync());
         }
         catch
         {
             return(null);
         }
     }
 }
Exemplo n.º 4
0
 // Returns Employees where their names contain the given string
 public async Task <PersonPhone> GetByIdAsync(int id)
 {
     // make a disposable connection
     using (var context = new AdventureWorks2017Context())
     {
         try
         {
             return(await context.PersonPhone.FirstOrDefaultAsync(e => e.BusinessEntityId == id));
         }
         catch
         {
             return(null);
         }
     }
 }
 // Returns Person where their names contain the given string
 public async Task <IEnumerable <Person> > GetByNameAsync(string regex)
 {
     using (var context = new AdventureWorks2017Context())
     {
         try
         {
             return(await context.Person.Where(p => (p.FirstName + p.MiddleName + p.LastName)
                                               .Contains(regex)).ToListAsync());
         }
         catch
         {
             return(null);
         }
     }
 }