Skip to content

Commit 18341c4

Browse files
Merge pull request #104 from johelvisguzman/dev
Merge with '2.3.0'
2 parents ff2c885 + d590b65 commit 18341c4

File tree

54 files changed

+2299
-734
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2299
-734
lines changed

samples/DotNetToolkit.Repository.Wpf.Demo/Infrastructure/FormViewModelBase.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ public abstract class FormViewModelBase<TValidator> : ViewModelBase where TValid
1414

1515
#endregion
1616

17+
#region Events
18+
19+
public event EventHandler Submitted;
20+
21+
#endregion
22+
1723
#region Properties
1824

1925
public bool IsDirty
@@ -42,7 +48,7 @@ protected FormViewModelBase()
4248

4349
#endregion
4450

45-
#region Implementation of IValidatable
51+
#region Public Methods
4652

4753
public virtual async Task<bool> ValidateAsync()
4854
{
@@ -61,5 +67,17 @@ public virtual async Task<bool> ValidateAsync()
6167
}
6268

6369
#endregion
70+
71+
#region Protected Methods
72+
73+
protected async void OnSubmitAsync()
74+
{
75+
if (await ValidateAsync())
76+
{
77+
Submitted?.Invoke(this, EventArgs.Empty);
78+
}
79+
}
80+
81+
#endregion
6482
}
6583
}

samples/DotNetToolkit.Repository.Wpf.Demo/ViewModels/CustomerFormViewModel.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,11 @@ public DateTime? Date
4747

4848
#endregion
4949

50-
#region Events
51-
52-
public event EventHandler Submitted;
53-
54-
#endregion
55-
5650
#region Constructors
5751

5852
public CustomerFormViewModel()
5953
{
60-
SubmitCommand = new RelayCommand(OnSubmit);
61-
}
62-
63-
#endregion
64-
65-
#region Private Methods
66-
67-
private async void OnSubmit()
68-
{
69-
if (await ValidateAsync())
70-
{
71-
Submitted?.Invoke(this, EventArgs.Empty);
72-
}
54+
SubmitCommand = new RelayCommand(OnSubmitAsync);
7355
}
7456

7557
#endregion

src/DotNetToolkit.Repository.AdoNet/AdoNetRepository.cs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace DotNetToolkit.Repository.AdoNet
22
{
3-
using Logging;
3+
using Interceptors;
4+
using System.Collections.Generic;
45

56
/// <summary>
67
/// Represents a repository for entity framework.
@@ -9,45 +10,71 @@ public class AdoNetRepository<TEntity, TKey> : AdoNetRepositoryBase<TEntity, TKe
910
{
1011
#region Constructors
1112

13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="AdoNetRepository{TEntity, TKey}" /> class.
15+
/// </summary>
16+
/// <param name="connectionString">The connection string.</param>
17+
public AdoNetRepository(string connectionString) : base(connectionString) { }
18+
1219
/// <summary>
1320
/// Initializes a new instance of the <see cref="AdoNetRepository{TEntity, TKey}" /> class.
1421
/// </summary>
1522
/// <param name="providerName">The name of the provider.</param>
1623
/// <param name="connectionString">The connection string.</param>
1724
public AdoNetRepository(string providerName, string connectionString) : base(providerName, connectionString) { }
1825

26+
/// <summary>
27+
/// Initializes a new instance of the <see cref="AdoNetRepository{TEntity, TKey}" /> class.
28+
/// </summary>
29+
/// <param name="connectionString">The connection string.</param>
30+
/// <param name="interceptors">The interceptors.</param>
31+
public AdoNetRepository(string connectionString, IEnumerable<IRepositoryInterceptor> interceptors) : base(connectionString, interceptors) { }
32+
1933
/// <summary>
2034
/// Initializes a new instance of the <see cref="AdoNetRepository{TEntity, TKey}" /> class.
2135
/// </summary>
2236
/// <param name="providerName">The name of the provider.</param>
2337
/// <param name="connectionString">The connection string.</param>
24-
/// <param name="logger">The logger.</param>
25-
public AdoNetRepository(string providerName, string connectionString, ILogger logger) : base(providerName, connectionString, logger) { }
38+
/// <param name="interceptors">The interceptors.</param>
39+
public AdoNetRepository(string providerName, string connectionString, IEnumerable<IRepositoryInterceptor> interceptors) : base(providerName, connectionString, interceptors) { }
2640

2741
#endregion
2842
}
2943

3044
/// <summary>
3145
/// Represents a repository for entity framework with a default primary key value of type integer.
3246
/// </summary>
33-
public class AdoNetRepository<TEntity> : AdoNetRepositoryBase<TEntity, int>, IRepository<TEntity> where TEntity : class
47+
public class AdoNetRepository<TEntity> : AdoNetRepositoryBase<TEntity, int>, IRepositoryAsync<TEntity> where TEntity : class
3448
{
3549
#region Constructors
3650

3751
/// <summary>
38-
/// Initializes a new instance of the <see cref="AdoNetRepository{TEntity, TKey}" /> class.
52+
/// Initializes a new instance of the <see cref="AdoNetRepository{TEntity}" /> class.
53+
/// </summary>
54+
/// <param name="connectionString">The connection string.</param>
55+
public AdoNetRepository(string connectionString) : base(connectionString) { }
56+
57+
/// <summary>
58+
/// Initializes a new instance of the <see cref="AdoNetRepository{TEntity}" /> class.
3959
/// </summary>
4060
/// <param name="providerName">The name of the provider.</param>
4161
/// <param name="connectionString">The connection string.</param>
4262
public AdoNetRepository(string providerName, string connectionString) : base(providerName, connectionString) { }
4363

4464
/// <summary>
45-
/// Initializes a new instance of the <see cref="AdoNetRepository{TEntity, TKey}" /> class.
65+
/// Initializes a new instance of the <see cref="AdoNetRepository{TEntity}" /> class.
66+
/// </summary>
67+
/// <param name="connectionString">The connection string.</param>
68+
/// <param name="interceptors">The interceptors.</param>
69+
public AdoNetRepository(string connectionString, IEnumerable<IRepositoryInterceptor> interceptors) : base(connectionString, interceptors) { }
70+
71+
/// <summary>
72+
/// Initializes a new instance of the <see cref="AdoNetRepository{TEntity}" /> class.
4673
/// </summary>
4774
/// <param name="providerName">The name of the provider.</param>
4875
/// <param name="connectionString">The connection string.</param>
49-
/// <param name="logger">The logger.</param>
50-
public AdoNetRepository(string providerName, string connectionString, ILogger logger) : base(providerName, connectionString, logger) { }
76+
/// <param name="interceptors">The interceptors.</param>
77+
public AdoNetRepository(string providerName, string connectionString, IEnumerable<IRepositoryInterceptor> interceptors) : base(providerName, connectionString, interceptors) { }
5178

5279
#endregion
5380
}

src/DotNetToolkit.Repository.AdoNet/AdoNetRepositoryBase.cs

Lines changed: 30 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
{
33
using FetchStrategies;
44
using Helpers;
5+
using Interceptors;
56
using Internal;
6-
using Logging;
77
using Properties;
88
using Queries;
99
using Specifications;
1010
using System;
1111
using System.Collections.Concurrent;
1212
using System.Collections.Generic;
13+
using System.Configuration;
1314
using System.Data;
1415
using System.Data.Common;
1516
using System.Linq;
@@ -22,7 +23,7 @@
2223
/// <summary>
2324
/// Represents a repository for ado.net.
2425
/// </summary>
25-
public abstract class AdoNetRepositoryBase<TEntity, TKey> : RepositoryAsyncBase<TEntity, TKey> where TEntity : class
26+
public abstract class AdoNetRepositoryBase<TEntity, TKey> : RepositoryBaseAsync<TEntity, TKey> where TEntity : class
2627
{
2728
#region Fields
2829

@@ -66,14 +67,37 @@ public abstract class AdoNetRepositoryBase<TEntity, TKey> : RepositoryAsyncBase<
6667

6768
#region Constructors
6869

70+
/// <summary>
71+
/// Initializes a new instance of the <see cref="AdoNetRepositoryBase{TEntity, TKey}"/> class.
72+
/// </summary>
73+
/// <param name="connectionString">The connection string.</param>
74+
/// <param name="interceptors">The interceptors.</param>
75+
protected AdoNetRepositoryBase(string connectionString, IEnumerable<IRepositoryInterceptor> interceptors = null) : base(interceptors)
76+
{
77+
if (string.IsNullOrEmpty(connectionString))
78+
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmptyString, nameof(connectionString));
79+
80+
var ccs = ConfigurationManager.ConnectionStrings[connectionString];
81+
if (ccs == null)
82+
throw new ArgumentException(Resources.ConnectionStringDoestNotExistInConfigFile);
83+
84+
Factory = Internal.DbProviderFactories.GetFactory(ccs.ProviderName);
85+
ConnectionString = connectionString;
86+
87+
Initialize();
88+
}
89+
6990
/// <summary>
7091
/// Initializes a new instance of the <see cref="AdoNetRepositoryBase{TEntity, TKey}"/> class.
7192
/// </summary>
7293
/// <param name="providerName">The name of the provider.</param>
7394
/// <param name="connectionString">The connection string.</param>
74-
/// <param name="logger">The logger.</param>
75-
protected AdoNetRepositoryBase(string providerName, string connectionString, ILogger logger = null) : base(logger)
95+
/// <param name="interceptors">The interceptors.</param>
96+
protected AdoNetRepositoryBase(string providerName, string connectionString, IEnumerable<IRepositoryInterceptor> interceptors = null) : base(interceptors)
7697
{
98+
if (string.IsNullOrEmpty(providerName))
99+
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmptyString, nameof(providerName));
100+
77101
if (string.IsNullOrEmpty(connectionString))
78102
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmptyString, nameof(connectionString));
79103

@@ -1686,7 +1710,7 @@ private TEntity AutoMap(DbDataReader r, DbSqlSelectStatementConfig config)
16861710

16871711
#endregion
16881712

1689-
#region Overrides of RepositoryBase<TEntity,TKey>
1713+
#region Overrides of RepositoryBase<TEntity, TKey>
16901714

16911715
/// <summary>
16921716
/// A protected overridable method for adding the specified <paramref name="entity" /> into the repository.
@@ -1769,19 +1793,6 @@ protected override TEntity GetEntity(TKey key, IFetchStrategy<TEntity> fetchStra
17691793
return ExecuteObject<TEntity>(config.Sql, config.Parameters, r => AutoMap(r, config));
17701794
}
17711795

1772-
/// <summary>
1773-
/// Gets an entity that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
1774-
/// </summary>
1775-
protected override TEntity GetEntity(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options)
1776-
{
1777-
if (criteria == null)
1778-
throw new ArgumentNullException(nameof(criteria));
1779-
1780-
PrepareSelectStatement(criteria, options, out DbSqlSelectStatementConfig config);
1781-
1782-
return ExecuteObject<TEntity>(config.Sql, config.Parameters, r => AutoMap(r, config));
1783-
}
1784-
17851796
/// <summary>
17861797
/// Gets an entity that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
17871798
/// </summary>
@@ -1798,16 +1809,6 @@ protected override TResult GetEntity<TResult>(ISpecification<TEntity> criteria,
17981809
return ExecuteObject<TResult>(config.Sql, config.Parameters, r => AutoMap<TResult>(r, selector, config));
17991810
}
18001811

1801-
/// <summary>
1802-
/// Gets a collection of entities that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
1803-
/// </summary>
1804-
protected override IEnumerable<TEntity> GetEntities(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options)
1805-
{
1806-
PrepareSelectStatement(criteria, options, out DbSqlSelectStatementConfig config);
1807-
1808-
return ExecuteList<TEntity>(config.Sql, config.Parameters, r => AutoMap(r, config));
1809-
}
1810-
18111812
/// <summary>
18121813
/// Gets a collection of entities that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
18131814
/// </summary>
@@ -1916,7 +1917,7 @@ public override void Dispose()
19161917

19171918
#endregion
19181919

1919-
#region Overrides of RepositoryAsyncBase<TEntity,TKey>
1920+
#region Overrides of RepositoryBaseAsync<TEntity, TKey>
19201921

19211922
/// <summary>
19221923
/// A protected asynchronous overridable method for saving changes made in the current unit of work in the repository.
@@ -1965,19 +1966,6 @@ public override void Dispose()
19651966
return ExecuteObjectAsync<TEntity>(config.Sql, config.Parameters, r => AutoMap(r, config), cancellationToken);
19661967
}
19671968

1968-
/// <summary>
1969-
/// A protected asynchronous overridable method for getting an entity that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
1970-
/// </summary>
1971-
protected override Task<TEntity> GetEntityAsync(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken())
1972-
{
1973-
if (criteria == null)
1974-
throw new ArgumentNullException(nameof(criteria));
1975-
1976-
PrepareSelectStatement(criteria, options, out DbSqlSelectStatementConfig config);
1977-
1978-
return ExecuteObjectAsync<TEntity>(config.Sql, config.Parameters, r => AutoMap(r, config), cancellationToken);
1979-
}
1980-
19811969
/// <summary>
19821970
/// A protected asynchronous overridable method for getting an entity that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
19831971
/// </summary>
@@ -1994,24 +1982,11 @@ public override void Dispose()
19941982
return ExecuteObjectAsync<TResult>(config.Sql, config.Parameters, r => AutoMap<TResult>(r, selector, config), cancellationToken);
19951983
}
19961984

1997-
/// <summary>
1998-
/// A protected asynchronous overridable method for getting a collection of entities that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
1999-
/// </summary>
2000-
protected override Task<IEnumerable<TEntity>> GetEntitiesAsync(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken())
2001-
{
2002-
PrepareSelectStatement(criteria, options, out DbSqlSelectStatementConfig config);
2003-
2004-
return ExecuteListAsync<TEntity>(config.Sql, config.Parameters, r => AutoMap(r, config), cancellationToken);
2005-
}
2006-
20071985
/// <summary>
20081986
/// A protected asynchronous overridable method for getting a collection of entities that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
20091987
/// </summary>
20101988
protected override Task<IEnumerable<TResult>> GetEntitiesAsync<TResult>(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options, Expression<Func<TEntity, TResult>> selector, CancellationToken cancellationToken = new CancellationToken())
20111989
{
2012-
if (criteria == null)
2013-
throw new ArgumentNullException(nameof(criteria));
2014-
20151990
if (selector == null)
20161991
throw new ArgumentNullException(nameof(selector));
20171992

0 commit comments

Comments
 (0)