Entity Classes
Definition
In JFW, each Entity Class (named as C
+ Entity name
, such as CUser) is a class that represents a data table. It has properties and methods that can be used to manipulate the data.
Get Entity List
To retrieve all entities from the database, you can use the static method List. If the method supports it, you can filter the entity list by passing some parameters to the method.
List<CUser> users = CUser.List();
Add an Entity
To add a new single Entity, create a new Entity object and then call the Add method to insert the object into the database.
CUser aNewUser = new CUser
{
BrandId = 1,
Username = "admin"
Password = "@Abc123456",
UserType = (short)UserType.EndUser,
Status = 1
};
CUser aNewCreatedUser = CUser.Add(aNewUser); // After we add the object to database, we will process data and return a new created object with updated fields.
Get an Entity
A static method called Get can retrieve an Entity if you pass its ID as an argument. Alternatively, you can use other static methods that start with GetBy... to get an Entity based on different criteria.
CUser aUser = CUser.Get(1); // If there is no Entity with ID = 1, aUser will be null.
Update an Entity
To modify the Entity in the database, you can use the Update method.
// This example shows how to edit an existing Entity.
aUser.Status = (short)UserStatus.Inactive;
aUser.Password = "!JFW123456";
CUser.Update(aUser); // We send the Entity data to update it in the database
aUser.Reload(); // We call this method to refresh our data to the latest one from the database in case there are some changes in auto-generated fields.
Delete an Entity
To delete an Entity, you need to pass its ID to the Delete method. Some methods can also delete an Entity based on other fields.
// We assume that we have User with ID = 5 in our database
CUser.Delete(5);
Entity Class List
Last updated
Was this helpful?