Tuesday, 15 January 2013

c# - Linq Expression tree preprocessing. Debugger issue -



c# - Linq Expression tree preprocessing. Debugger issue -

i read article how entityframework translates expressions sql queries. interesting part how ef preprocess look tree exclude closures, , local properties tree , replace them actual value. here code. trying figure out when , in cases local properties evaluates. can't grab moment debugger. see state changes.

private bool _called1; private bool _called2; protected bool noob1 { { debugger.break(); // never works _called1 = true; // changes true homecoming true; } } public bool noob2 { { debugger.break(); // never works _called2 = true; // changes true homecoming false; } } public actionresult index() { var dn = new applicationdbcontext(); var q1 = dn.heros.where(h => h.isnoob == noob1); dn.heros.where(h => h.isnoob == noob2); var result = this.gettype().getmethod("about").invoke(this, null); // test breakpoint within action. phone call using reflection homecoming content(string.format("c1={0}; c2={1}", _called1, _called2)); } public actionresult about() { // if place breakpoint here fires, no problem debugger , invoking through reflection viewbag.message = "your application description page."; homecoming view(); }

every time run code _called1 or _called2 true. both true. breakpoints didn't work within properties. how possible? why _called1 , _called2 alter values unpredictable? how see thead callstack when ef preprocess look tree?

public class applicationdbcontext : identitydbcontext<applicationuser> { public applicationdbcontext() : base("defaultconnection", throwifv1schema: false) { } public dbset<hero> heros { get; set; } public static applicationdbcontext create() { homecoming new applicationdbcontext(); } }

p.s. after finished writing question understand write heros set wrong dbcontext. don't think can cause problem.

c# linq entity-framework debugging reflection

No comments:

Post a Comment