entity framework - DbScanExpression with join and left table select -
colleagues.
i have group of classes(tables) have common properties(columns). using entityframework intercept select queries , modify them.
i add join , clauses. don't know how project left table without explicit properties selection.
initial query this: context.loans
sql
select [loannumber] [loannumber], [sec_owner] [sec_owner] [dbo].[loans]
should modified following:
select o.loannumber loannumber, o.sec_owner sec_owner, dbo.loans o left outer join dbo.users u on o.sec_owner = u.sec_id , u.name = n'root' ((256 = (o.sec_permissions & 256)) , (o.sec_owner = u.sec_id)) var joinexpression = expression.leftouterjoin( userentitybase.scan(), (l, r) => l.property("sec_owner").equal(r.property("sec_id")) .and(r.property("name").equal(dbexpression.fromstring(this.username))) ) .where( exp => dbexpressionbuilder .constant((int)accesspermissions.ownerread).equal(exp.property("l").property("sec_permissions").bitwiseand(dbexpressionbuilder.constant((int)accesspermissions.ownerread))) .and(exp.property("l").property("sec_owner").equal(exp.property("r").property("sec_id"))) );
as understand join projects columns both table. need project initial select without knowing it.
select [loannumber] [loannumber], [sec_owner] [sec_owner]
thanks in advance,
/artem
as work around issue removed join query , decided use subselects.
public override dbexpression visit(dbscanexpression expression) {
...
var userentitybase = expression.target.entitycontainer.getentitysetbyname("user", true); var newexpression = expression .where( exp => ... .and(exp.property("sec_owner") .equal(userentitybase.scan().where(user => user.property("name").equal(dbexpression.fromstring(username))).select(u => u.property("sec_id")).take(1).element()) ) ) ... ); ... return base.visit(expression); }
.select(u => u.property("sec_id")).take(1).element() evaluates select top 1
Comments
Post a Comment