簡體   English   中英

如何在代碼隱藏中設置 EntityDataSource 的 Where 子句

[英]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;

當我刪除 Where 子句時,我的 gridview 會返回所有記錄。 當我硬編碼從 HTML 中的 HttpContexxt 字符串生成的相同字符串時,我的 gridview 返回正確的記錄。 但是,當我嘗試使用上面的代碼時,我收到了一條 out of scope 消息:

在當前 scope 或上下文中無法解析“kwingat”。 確保所有引用的變量都在 scope 中,加載了所需的模式,並且正確引用了命名空間。 接近簡單標識符,第 6 行,第 15 列。

有任何想法嗎?

我認為您需要將其作為參數傳遞

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM