- FreeSql.Repository 增加 filter 参数,现实数据过滤 + 验证;

如:var postRepos = fsql.GetGuidRepository<Post>(a => a.TopicId == 1); postRepos CURD 方法都会以 lambad 条件作为查询或验证,Update/Insert验证错误时会抛出异常。
- ISelect 增加 First/FirstAsync;
This commit is contained in:
28810
2019-03-02 20:46:26 +08:00
parent a2f4a8bcd8
commit 30385d2e91
10 changed files with 84 additions and 34 deletions

View File

@ -203,6 +203,7 @@ namespace FreeSql.Internal {
}
internal string ExpressionLambdaToSql(Expression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, Func<Expression[], string> getSelectGroupingMapString, SelectTableInfoType tbtype, bool isQuoteName) {
if (exp == null) return "";
switch (exp.NodeType) {
case ExpressionType.Not: return $"not({ExpressionLambdaToSql((exp as UnaryExpression)?.Operand, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName)})";
case ExpressionType.Quote: return ExpressionLambdaToSql((exp as UnaryExpression)?.Operand, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName);

View File

@ -205,6 +205,9 @@ namespace FreeSql.Internal.CommonProvider {
return (await this.ToListAsync()).FirstOrDefault();
}
public T1 First() => this.ToOne();
public Task<T1> FirstAsync() => this.ToOneAsync();
protected List<TReturn> ToListMapReader<TReturn>((ReadAnonymousTypeInfo map, string field) af) {
var sql = this.ToSql(af.field);
if (_cache.seconds > 0 && string.IsNullOrEmpty(_cache.key)) _cache.key = $"{sql}{string.Join("|", _params.Select(a => a.Value))}";
@ -461,7 +464,7 @@ namespace FreeSql.Internal.CommonProvider {
return (await this.ToListMapReaderAsync<TReturn>((map, field.Length > 0 ? field.Remove(0, 2).ToString() : null))).FirstOrDefault();
}
protected TSelect InternalWhere(Expression exp) => this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp, null));
protected TSelect InternalWhere(Expression exp) => exp == null ? this as TSelect : this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp, null));
protected TSelect InternalJoin(Expression exp) {
return this as TSelect;