CRUD
Alejandro Cernuda
TweetCreate, read, update and delete (CRUD) These are the basic operations performed on a dataset. They are also the most common. All methods of the library exist in their synchronous and asynchronous versions. Whenever possible, we recommend using the latter.
Simple CRUD Examples
publicasync TaskTestInsertAsyn(User user)
{
DataGather dg = DataGather.GetInstance(ConnectionString);
await dg.InsertAsync(user);
}
As you can see, if there is a table named User in the database and it has the same fields as the User object and also a primary key, you do not need to specify anything else.
public User: IAR
{
...
}
And much better if the User class inherits from
///
/// When inheriting from it, any class in the database will have fields normally used in a sql Table; as well as its initialization.
///
publicabstractclassIAR
{
publicint Id { get; set; }
///
/// This property will be initialized as true.
///
publicbool Active { get; set; }
///
/// This property will be initialized with the current date
///
public DateTime RowUpdateDate { get; set; }
publicIAR()
{
Active = true;
RowUpdateDate = DateTime.Now;
}
}
Get Example
publicasync Task<User> GetAsync()
{
return (await dg.GetAsync<User>()).ToList();
}
We can also delete records in a simple way, as long as the table has a primary key.
await dg.DeleteAsync(user)
await dg.UpdateAsync(user);
Obtaining data from multiple tables
In real life it is difficult to structure the data so that there is always a table or view for the class we need in the code. SQLClientCoreTool can work with this incongruity. The following example requires bringing all the data from the PostGroup table and also the language from the Langs table. Note that instead of a query en string we could pass the name of a stored procedure and have the SQl code on the server itself.
}