kyle
kyle

Reputation: 527

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?

Upvotes: 3

Views: 6083

Answers (1)

rkw
rkw

Reputation: 7297

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()));

Upvotes: 2

Related Questions