Skip to content

Commit 29aba46

Browse files
committed
added public save methods
1 parent fa851ee commit 29aba46

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

src/GenericSQLEntityHandler/GenericSQLEntityHandler.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,50 @@ public GenericSQLEntityHandler(SqlConnection sqlConnection)
4545

4646
#region Save Methods
4747

48+
/// <summary>
49+
/// Saves a single entity to the database.
50+
/// </summary>
51+
/// <param name="entity">The entity to save.</param>
52+
/// <param name="table">The name of the table to save to.</param>
53+
/// <param name="identityColumns">Only used for Update and InsertOrUpdate. Must contain the columns that identify the entity (Case sensitive).</param>
54+
/// <param name="saveType">To save to or update the database, InsertOrUpdate handles a mixed list, but has a little overhead. FastInsert will not select the autogen column after an insert.</param>
55+
/// <param name="autoGenIdColumn">If an autoincrement column is in the table, on insert it sets the new id to the inserted entitys corresponding property (Case sensitive).</param>
56+
/// <returns>Returns true if the entity is saved/updated, else false.</returns>
57+
public bool SaveEntity<T>(T entity, string table, string[] identityColumns, SaveType saveType, string autoGenIdColumn) where T : class
58+
{
59+
return SaveEntityList(new List<T>(new[] { entity }), table, identityColumns, saveType, autoGenIdColumn, false, null);
60+
}
61+
62+
/// <summary>
63+
/// Saves a list of entities to the database.
64+
/// </summary>
65+
/// <param name="entityList">List of entities to save.</param>
66+
/// <param name="table">The name of the table to save to.</param>
67+
/// <param name="identityColumns">Only used for Update and InsertOrUpdate. Must contain the columns that identify the entity (Case sensitive).</param>
68+
/// <param name="saveType">To save or update the database, InsertOrUpdate handles a mixed list, but has a little overhead. FastInsert will not select the autogen column after an insert.</param>
69+
/// <param name="autoGenIdColumn">If an autoincrement column is in the table, on insert it sets the new id to the inserted entitys corresponding property (Case sensitive).</param>
70+
/// <returns>Returns true if all entities are saved/updated, else false.</returns>
71+
public bool SaveEntities<T>(List<T> entityList, string table, string[] identityColumns, SaveType saveType, string autoGenIdColumn) where T : class
72+
{
73+
return SaveEntityList(entityList, table, identityColumns, saveType, autoGenIdColumn, false, null);
74+
}
75+
76+
/// <summary>
77+
/// Saves a list of entities to the database.
78+
/// </summary>
79+
/// <param name="entityList">List of entities to save.</param>
80+
/// <param name="table">The name of the table to save to.</param>
81+
/// <param name="identityColumns">Only used for Update and InsertOrUpdate. Must contain the columns that identify the entity (Case sensitive).</param>
82+
/// <param name="saveType">To save or update the database, InsertOrUpdate handles a mixed list, but has a little overhead. FastInsert will not select the autogen column after an insert.</param>
83+
/// <param name="autoGenIdColumn">If an autoincrement column is in the table, on insert it sets the new id to the inserted entitys corresponding property (Case sensitive).</param>
84+
/// <param name="fetchAutoGenIdColumnOnUpdate">True if the auto gen id column should be fetched on update, on insert it already does</param>
85+
/// <param name="propertiesToIgnore">Specify an array of property names, that should not be inserted/updated in the DB</param>
86+
/// <returns>Returns true if all entities are saved/updated, else false.</returns>
87+
public bool SaveEntities<T>(List<T> entityList, string table, string[] identityColumns, SaveType saveType, string autoGenIdColumn, bool fetchAutoGenIdColumnOnUpdate, string[] propertiesToIgnore) where T : class
88+
{
89+
return SaveEntityList(entityList, table, identityColumns, saveType, autoGenIdColumn, fetchAutoGenIdColumnOnUpdate, propertiesToIgnore);
90+
}
91+
4892
private bool SaveEntityList<T>(List<T> entities, string table, string[] identityColumns, SaveType saveType,
4993
string autoGenIdColumn, bool fetchAutoGenIdColumnOnUpdate, string[] propertiesToIgnore) where T : class
5094
{

0 commit comments

Comments
 (0)