Simple CRUD helpers for Dapper based on .NET Standard 1.3
Dapper.SimpleCRUD.Core is a porting for the .NET Standard 1.3 of the excelent extension for Dapper created by Eric Coffman.
See usage instructions in Eric Coffman's original project in https://github.com/ericdc1/Dapper.SimpleCRUD.
This version has also the following changes and improvements:
The following functions have a new overload able to receive the 'string[] propertiesToBeIgnored' parameter to be able to define whick fields you don't want to retrieve:
- Get<Type>(..., string[] propertiesToBeIgnored, ...)
- GetList<Type>(..., string[] propertiesToBeIgnored, ...)
- GetListPaged<Type>(..., string[] propertiesToBeIgnored, ...)
By using this parameter you can specify which properties you don't want to be retrieved from the database. This is usefull to avoid the read of large and sensitive fields.
The following functions were added to allow the update of non-nulled fields of an object.
public static int UpdateNonNullProps(this IDbConnection connection, TEntity entityToUpdate, IDbTransaction transaction = null, int? commandTimeout = null);
public static Task<int> UpdateNonNullPropsAsync<TEntity>(this IDbConnection connection, TEntity entityToUpdate, IDbTransaction transaction = null, int? commandTimeout = null, System.Threading.CancellationToken? token = null);
Example usage:
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Status { get; set; }
}
...
// change only the status of a user
connection.UpdateNonNullProps( new User{ Id=1, Status="inactive" });
This is useful when we only want to update certain properties of the object with no need to read the object from database, change the properties and re-save it back. This is more performant and also more thread safe as you only need one operation to update the object.
But be aware with non-nullable properties because these will always be updated.
public static void UpdateManyToManyRelations<ManyToManyTable>(this IDbConnection connection,
string parentEntityIdFieldName, object parentId,
string childEntityIdFieldName, IEnumerable<Guid> newChildIds,
IDbTransaction transaction = null, int? commandTimeout = null)
With this function you need only to provide the new list of items(newChildIds) to be linked with a parent object(parentEntityIdFieldName/parentId) in the <ManyToManyTable>