我有一个EntityDataSource,我需要将WHERE设置为本地变量类型:GUID。

我的问题是我无法将本地变量Guid发送到EntityDataSource进行WHERE操作。

我还尝试使用ControlParameter <asp:ControlParameter Name="UserId" />,并在Guid上将String的Text属性带标签转换为String。但是不起作用。

任何想法如何解决这个问题

   <asp:EntityDataSource ID="EntityDataSourceListAuthors" runat="server"
        AutoGenerateWhereClause="True"
        ConnectionString="name=CmsConnectionStringEntityDataModel"
        DefaultContainerName="CmsConnectionStringEntityDataModel"
        EnableFlattening="False" EntitySetName="CmsAuthors" Where=""
        EntityTypeFilter="" Select="">
        <WhereParameters>
            <asp:Parameter Name="UserId" />
        </WhereParameters>
    </asp:EntityDataSource>

最佳答案

解决哟我的问题:


添加对象类型的自定义参数


有用的资源:

http://www.leftslipper.com/ShowFaq.aspx?FaqId=11

http://weblogs.asp.net/scottgu/archive/2006/01/23/436276.aspx

How to programmatically set parameters for EntityDataSource and DetailsView?

http://msdn.microsoft.com/en-us/library/cc294876%28v=Expression.40%29.aspx

http://msdn.microsoft.com/en-us/library/cc295043%28v=Expression.40%29.aspx

http://weblogs.asp.net/scottgu/archive/2006/11/26/tip-trick-how-to-register-user-controls-and-custom-controls-in-web-config.aspx

现在我的代码

<asp:EntityDataSource ID="EntityDataSourceListAuthors" runat="server"
        AutoGenerateWhereClause="True"
        ConnectionString="name=CmsConnectionStringEntityDataModel"
        DefaultContainerName="CmsConnectionStringEntityDataModel"
        EnableFlattening="False" EntitySetName="CmsAuthors" Where=""
        EntityTypeFilter="" Select="">
        <WhereParameters>
            <cmsParameter:CustomParameter Name="UserId" />
        </WhereParameters>
    </asp:EntityDataSource>




新增班级:

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Web.Security;

namespace WebProject.Core.Utilities
{
    public class CustomParameter : Parameter
    {
        protected override object Evaluate(HttpContext context, Control control)
        {
            MembershipUser currentUser = Membership.GetUser();
            return currentUser.ProviderUserKey;
        }
    }
}

09-07 01:31