public Tuple <TSource, TTarget1, TTarget2> Scalar <TSource, TTarget1, TTarget2>(FromExpression <TSource> fromCondition, WhereExpression <TSource> whereCondition, TransactionContext transContext) where TSource : DatabaseEntity, new() where TTarget1 : DatabaseEntity, new() where TTarget2 : DatabaseEntity, new() { IList <Tuple <TSource, TTarget1, TTarget2> > result = Retrieve <TSource, TTarget1, TTarget2>(fromCondition, whereCondition, transContext); if (result == null || result.Count == 0) { return(null); } if (result.Count > 1) { throw new DatabaseException($"Scalar retrieve return more than one result. From:{fromCondition.ToString()}, Where:{whereCondition.ToString()}"); //_logger.LogCritical(0, "retrieve result not one, but many." + typeof(TSource).FullName, null); //return null; } return(result[0]); }
public Task <Tuple <TSource, TTarget1, TTarget2> > ScalarAsync <TSource, TTarget1, TTarget2>(FromExpression <TSource> fromCondition, WhereExpression <TSource> whereCondition, TransactionContext transContext) where TSource : DatabaseEntity, new() where TTarget1 : DatabaseEntity, new() where TTarget2 : DatabaseEntity, new() { return(RetrieveAsync <TSource, TTarget1, TTarget2>(fromCondition, whereCondition, transContext) .ContinueWith(t => { IList <Tuple <TSource, TTarget1, TTarget2> > lst = t.Result; if (lst == null || lst.Count == 0) { return null; } if (lst.Count > 1) { throw new DatabaseException($"Scalar retrieve return more than one result. From:{fromCondition.ToString()}, Where:{whereCondition.ToString()}"); //_logger.LogCritical(0, "retrieve result not one, but many." + typeof(TSource).FullName, null); //return null; } return lst[0]; }, TaskScheduler.Default)); }
public T Scalar <T>(SelectExpression <T> selectCondition, FromExpression <T> fromCondition, WhereExpression <T> whereCondition, TransactionContext transContext) where T : DatabaseEntity, new() { IList <T> result = Retrieve <T>(selectCondition, fromCondition, whereCondition, transContext); if (result == null || result.Count == 0) { return(null); } if (result.Count > 1) { //_logger.LogCritical(0, "retrieve result not one, but many." + typeof(T).FullName, null); throw new DatabaseException($"Scalar retrieve return more than one result. Select:{selectCondition.ToString()}, From:{fromCondition.ToString()}, Where:{whereCondition.ToString()}"); } return(result[0]); }
public Task <T> ScalarAsync <T>(SelectExpression <T> selectCondition, FromExpression <T> fromCondition, WhereExpression <T> whereCondition, TransactionContext transContext) where T : DatabaseEntity, new() { return(RetrieveAsync <T>(selectCondition, fromCondition, whereCondition, transContext) .ContinueWith(t => { IList <T> lst = t.Result; if (lst == null || lst.Count == 0) { return default; } if (lst.Count > 1) { throw new DatabaseException($"Scalar retrieve return more than one result. Select:{selectCondition.ToString()}, From:{fromCondition.ToString()}, Where:{whereCondition.ToString()}"); //_logger.LogCritical(0, "retrieve result not one, but many." + typeof(T).FullName, null); //return default; } return lst[0]; }, TaskScheduler.Default)); }