public class Customer : EntityBase { public string Name { get; set; } public string Address { get; set; } public string Phone { get; set; } public Customer() { // Set the entity name for the base class this.EntityName = "Customers"; } } // Usage Customer customer = new Customer(); customer.Name = "John Smith"; customer.Address = "123 Main St"; customer.Phone = "555-1234"; customer.Save();
public class Order : EntityBase { public int CustomerId { get; set; } public DateTime OrderDate { get; set; } public decimal TotalAmount { get; set; } public Order() { // Set the entity name for the base class this.EntityName = "Orders"; } public static ListIn this example, we are creating an Order entity object that also inherits from the EntityBase class. This entity has some custom properties for the customer ID, order date, and total amount. We have also implemented a static method called GetOrdersByCustomer that retrieves a list of orders for a specific customer from the database. This method uses the ExecuteQueryGetOrdersByCustomer(int customerId) { // Create a new instance of the EntityBase class EntityBase entity = new EntityBase(); // Build the SQL query string sql = "SELECT * FROM Orders WHERE CustomerId = @CustomerId"; // Create the parameters List parameters = new List (); parameters.Add(entity.CreateParameter("@CustomerId", customerId)); // Execute the query and return the results as a list of Order objects return entity.ExecuteQuery (sql, parameters); } } // Usage List orders = Order.GetOrdersByCustomer(123);