protected RepoBaseService(ClientOrderContext context) { this.Context = context; //Add this to ignore tracking in memory for entities. //This is usfull in application dat have a continues link with the database. //In web apps is recomanded to have a disconsinues connection, because we don't now when and if we will get any changes for an object. //For this pourpose we are traking each entitie when it was las modify and we have an proportie on our entities IsDirty that keeps this info. this.Context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; }
static void TestClientOrder() { using (ClientOrderContext context = new ClientOrderContext()) { ClientModel c = new ClientModel() { Name = "Customer 1", Email = "Email" }; OrderModel o1 = new OrderModel() { Value = 200, Client = c }; OrderModel o2 = new OrderModel() { Value = 300, Client = c }; c.Orders.Add(o1); c.Orders.Add(o2); context.Clients.Add(c); context.Orders.Add(o1); context.Orders.Add(o2); context.SaveChanges(); var items = context.Clients; foreach (var x in items) { Console.WriteLine("Client : {0}, {1}, {2}", x.ClientId, x.Name, x.Email); foreach (var ox in x.Orders) { Console.WriteLine("\tOrders: {0}, {1}", ox.OrderId, ox.Value.ToString()); } } } }
public void CanAddAndUpdateSomeData() { var client = new Client { LastName = "Julie", FirstName = "Julie" }; using (var context = new ClientOrderContext(_options)) { context.Add(client); context.SaveChanges(); } client.FirstName += "t"; using (var context = new ClientOrderContext(_options)) { context.Clients.Update(client); context.SaveChanges(); } using (var context = new ClientOrderContext(_options)) { Assert.AreEqual("Juliet", context.Clients.FirstOrDefault().FirstName); } }
/// <summary> /// Constructor that establishes a connection between the database and the repository. /// </summary> /// <param name="context">Context to use.</param> public ClientRepository(ClientOrderContext context) { this.context = context; }
public ClientService(ClientOrderContext context) => this.context = context;
public ClientService(ClientOrderContext context) : base(context) { }