-
Notifications
You must be signed in to change notification settings - Fork 865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
查询的时候指定忽略列 #528
Labels
docs
This is a document
Comments
多表机制不好确定,暂时不提供该功能,以下扩展方法可以实现单表忽略查询: public static List<T1> ToListIgnore<T1>(this ISelect<T1> that, Expression<Func<T1, object>> selector)
{
if (selector == null) return that.ToList();
var s0p = that as Select0Provider;
var tb = s0p._tables[0];
var parmExp = tb.Parameter ?? Expression.Parameter(tb.Table.Type, tb.Alias);
var initExps = tb.Table.Columns.Values
.Where(a => a.Attribute.IsIgnore == false)
.Select(a => new
{
exp = Expression.Bind(tb.Table.Properties[a.CsName], Expression.MakeMemberAccess(parmExp, tb.Table.Properties[a.CsName])),
ignored = TestMemberExpressionVisitor.IsExists(selector, Expression.MakeMemberAccess(parmExp, tb.Table.Properties[a.CsName]))
})
.Where(a => a.ignored == false)
.Select(a => a.exp)
.ToArray();
var lambda = Expression.Lambda<Func<T1, T1>>(
Expression.MemberInit(
Expression.New(tb.Table.Type),
initExps
),
parmExp
);
return that.ToList(lambda);
}
class TestMemberExpressionVisitor : ExpressionVisitor
{
public string MemberExpString;
public bool Result { get; private set; }
public static bool IsExists(Expression selector, Expression memberExp)
{
var visitor = new TestMemberExpressionVisitor { MemberExpString = memberExp.ToString() };
visitor.Visit(selector);
return visitor.Result;
}
protected override Expression VisitMember(MemberExpression node)
{
if (!Result && node.ToString() == MemberExpString) Result = true;
return node;
}
} |
收到! |
大佬,能不能增加的时候定制某个特性忽略,但是查询的时候不忽略,反之查询的时候忽略某些列,修改或者删除添加的时候不忽略某些列,这样。多加几个不同的忽略特性 |
建议弄两个实体类进行操作,支持实体类继承 |
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
查询表数据转Dto的时候,如果只有特定几个内容过多的列不需要指定,写
new Dto(id){ a=R.a,b=R.b } 字段赋值需要很多
希望 可以忽略查询特定的少数列,例如 ingore(c=>c.t1.column1,c.t2.column2)。之类的语法。
The text was updated successfully, but these errors were encountered: