Skip to content

Commit 041c5e7

Browse files
committed
Update Query Generation to templates
1 parent d276dc8 commit 041c5e7

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

Helper/QueryHelper.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using DbSyncKit.DB.Attributes;
22
using DbSyncKit.DB.Interface;
33
using DbSyncKit.DB.Manager;
4+
5+
using System.ComponentModel.DataAnnotations;
46
using System.Text;
57
using System.Text.RegularExpressions;
68

@@ -91,6 +93,7 @@ public bool GetIncludeIdentityInsert<T>() where T : IDataContractComparer
9193
/// </summary>
9294
/// <typeparam name="T">The type for which to get the key columns. Must implement <see cref="IDataContractComparer"/>.</typeparam>
9395
/// <returns>A list of key column names.</returns>
96+
/// <seealso cref="IDataContractComparer"/>
9497
public List<string> GetKeyColumns<T>() where T : IDataContractComparer
9598
{
9699
return TypePropertyCacheManager.GetTypeProperties(typeof(T))
@@ -102,6 +105,7 @@ public List<string> GetKeyColumns<T>() where T : IDataContractComparer
102105
/// </summary>
103106
/// <typeparam name="T">The type for which to get the excluded properties. Must implement <see cref="IDataContractComparer"/>.</typeparam>
104107
/// <returns>A list of excluded property names.</returns>
108+
/// <seealso cref="IDataContractComparer"/>
105109
public List<string> GetExcludedProperties<T>() where T : IDataContractComparer
106110
{
107111
return TypePropertyCacheManager.GetTypeProperties(typeof(T))
@@ -113,11 +117,27 @@ public List<string> GetExcludedProperties<T>() where T : IDataContractComparer
113117
/// </summary>
114118
/// <typeparam name="T">The type for which to get all properties. Must implement <see cref="IDataContractComparer"/>.</typeparam>
115119
/// <returns>A list of all property names.</returns>
120+
/// <seealso cref="IDataContractComparer"/>
116121
public List<string> GetAllColumns<T>() where T : IDataContractComparer
117122
{
118123
return TypePropertyCacheManager.GetTypeProperties(typeof(T))
119124
.Select(prop => prop.Name).ToList();
120125
}
121126

127+
/// <summary>
128+
/// Retrieves a list of identity columns for a specified data contract type <typeparamref name="T"/>.
129+
/// </summary>
130+
/// <typeparam name="T">The type implementing the IDataContractComparer interface.</typeparam>
131+
/// <returns>A list containing the names of identity columns for the specified data contract type <typeparamref name="T"/>.</returns>
132+
/// <remarks>
133+
/// This method uses reflection to analyze the properties of the specified type <typeparamref name="T"/> and retrieves properties marked with a [Key] attribute, indicating identity columns.
134+
/// </remarks>
135+
/// <seealso cref="IDataContractComparer"/>
136+
public List<string> GetIdentityColumns<T>() where T : IDataContractComparer
137+
{
138+
return TypePropertyCacheManager.GetTypeProperties(typeof(T))
139+
.Where(prop => Attribute.IsDefined(prop, typeof(KeyAttribute))).Select(prop => prop.Name).ToList();
140+
}
141+
122142
}
123143
}

Interface/IQueryGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public interface IQueryGenerator
5959
/// <param name="entity">The entity for which the condition is generated.</param>
6060
/// <param name="keyColumns">The list of key columns used to create the condition.</param>
6161
/// <returns>A string representing the generated condition for a SQL WHERE clause.</returns>
62-
string GetCondition<T>(T entity, List<string> keyColumns) where T : IDataContractComparer;
62+
List<string> GetCondition<T>(T entity, List<string> keyColumns) where T : IDataContractComparer;
6363

6464
/// <summary>
6565
/// Escapes special characters in the input to make it SQL-safe.

QueryGenerationManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public string GenerateComment(string comment)
5454
}
5555

5656
/// <inheritdoc />
57-
public string GetCondition<T>(T entity, List<string> keyColumns) where T : IDataContractComparer
57+
public List<string> GetCondition<T>(T entity, List<string> keyColumns) where T : IDataContractComparer
5858
{
5959
return _querryGenerator.GetCondition<T>(entity, keyColumns);
6060
}

0 commit comments

Comments
 (0)