如何在代码隐藏中设置EntityDataSource的Where子句 [英] How do I set the Where clause of an EntityDataSource in the code-behind

查看:124
本文介绍了如何在代码隐藏中设置EntityDataSource的Where子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        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返回正确的记录。但是,当我尝试使用上面的代码时,我得到了超出范围的消息:

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'无法在当前范围或上下文中解决。确保所有引用的变量都在范围内,所需的模式被加载,并且该命名空间被正确引用。

'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.

任何想法?

推荐答案

我认为你需要作为参数传递

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

这篇关于如何在代码隐藏中设置EntityDataSource的Where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆