Data/CafeLib.Data.Sources/SqlCommandProvider.cs
/// <summary>
/// Insert or update an entity record.
/// </summary>
/// <typeparam name="TEntity">The type being inserted.</typeparam>
/// <param name="connectionInfo">Connection info</param>
/// <param name="data">Entity record</param>
/// <param name="expressions"></param>
/// <param name="token">Cancellation token</param>
/// <returns></returns>
Insert or update an entity record.
Insert or update an entity record .
public async Task<TEntity> UpsertAsync<TEntity>(IConnectionInfo connectionInfo, TEntity data, Expression<Func<TEntity, object>>[] expressions = null, CancellationToken token = default) where TEntity : class, IEntity
        {
            if (data == null) throw new ArgumentNullException(nameof(data));
            await using var connection = connectionInfo.GetConnection<T>();
            var id = await connection.MergeAsync(data, cancellationToken: token).ConfigureAwait(false);
            var propertyInfo = PrimaryCache.Get<TEntity>().PropertyInfo;
            propertyInfo.SetValue(data, Convert.ChangeType(id, propertyInfo.PropertyType));
            return data;
        }
public async Task < TEntity > UpsertAsync < TEntity > ( IConnectionInfo connectionInfo , TEntity data , Expression < Func < TEntity , object > > [ ] expressions = null , CancellationToken token = default ) where TEntity : class , IEntity { if ( data == null ) throw new ArgumentNullException ( nameof ( data ) ) ; await using var connection = connectionInfo . GetConnection < T > ( ) ; var id = await connection . MergeAsync ( data , cancellationToken : token ) . ConfigureAwait ( false ) ; var propertyInfo = PrimaryCache . Get < TEntity > ( ) . PropertyInfo ; propertyInfo . SetValue ( data , Convert . ChangeType ( id , propertyInfo . PropertyType ) ) ; return data ; }
Insert or update an entity record.
Insert or update an entity record .
None
connectionInfo
IConnectionInfo
None
data
TEntity
None
expressions
Expression<Func<TEntity, object>>[]
None
token
CancellationToken
None
typeparam
The type being inserted.
The type being inserted .