Database Reference
In-Depth Information
// each property and the entity as modified. Start by setting
// the state for the entity as 'Unchanged'.
entry.State = EntityState.Unchanged;
var databaseValues = entry.GetDatabaseValues();
entry.OriginalValues.SetValues(databaseValues);
}
}
context.SaveChanges();
}
return Request.CreateResponse(HttpStatusCode.OK, customer);
}
[HttpDelete]
[ActionName("Cleanup")]
public HttpResponseMessage Cleanup()
{
using (var context = new Recipe4Context())
{
context.Database.ExecuteSqlCommand("delete from chapter9.phone");
context.Database.ExecuteSqlCommand("delete from chapter9.customer");
return Request.CreateResponse(HttpStatusCode.OK);
}
}
}
Next we create the Visual Studio solution that will contain the client project that will consume the Web
API service.
10.
Create a new Visual Studio solution that contains a Console application entitled
Recipe3.Client .
11.
Replace the code in the program.cs file with that from Listing 9-26.
Listing 9-26. Our Windows Console Application That Serves as Our Test Client
internal class Program
{
private HttpClient _client;
private Customer _bush, _obama;
private Phone _whiteHousePhone, _bushMobilePhone, _obamaMobilePhone;
private HttpResponseMessage _response;
private static void Main()
{
Task t = Run();
t.Wait();
Console.WriteLine("\nPress <enter> to continue...");
Console.ReadLine();
}
 
Search WWH ::




Custom Search