简体   繁体   中英

How do I set the Where clause of an EntityDataSource in the code-behind

        PaymentsDueEntityDataSource.ContextTypeName = "Bills.DAL.BillsEntities";
        PaymentsDueEntityDataSource.EnableFlattening = false;
        PaymentsDueEntityDataSource.EntitySetName = "tblPayments_Due";

        PaymentsDueEntityDataSource.Where = "it.UserName = " + HttpContext.Current.User.Identity.Name.ToString();

        PaymentsDueEntityDataSource.Include = "tblType, tblRepeat";
        PaymentsDueEntityDataSource.EnableUpdate = true;

When I delete the Where clause, my gridview returns all records. When I hardcode the same string which is generated from the HttpContexxt string in the HTML, my gridview returns the proper records. However, when I try to use the code above, I get an out of scope message:

'kwingat' could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly. Near simple identifier, line 6, column 15.

Any Ideas?

I think you need to pass it as a parameter

PaymentsDueEntityDataSource.Where = "it.UserName = @UserID";
PaymentsDueEntityDataSource.WhereParameters.Add(new Parameter("UserID", TypeCode.Int32,  + HttpContext.Current.User.Identity.Name.ToString()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM