- 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

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>0.1.6</Version>
<Version>0.1.7</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors>
<Description>打造 .NETCore 最方便的 ORMDbFirst 与 CodeFirst 混合使用,提供从实体同步数据库,或者从数据库生成实体代码,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description>

View File

@ -28,6 +28,13 @@ namespace FreeSql {
T1 ToOne();
Task<T1> ToOneAsync();
/// <summary>
/// 执行SQL查询返回 T1 实体所有字段的第一条记录,记录不存在时返回 null
/// </summary>
/// <returns></returns>
T1 First();
Task<T1> FirstAsync();
/// <summary>
/// 返回即将执行的SQL语句
/// </summary>

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;