通过linq实例化的现有对象的访问属性

时间:2014-05-12 18:22:13

标签: c# .net binding

我正在使用.net 4.5表单和模型绑定。

我在控件上有一个select方法,它通过linq将我的Ex_Application对象的实例返回给DetailsView。

我的详情视图是:

    <asp:DetailsView ID="DetailsView_displayApp" runat="server"  DataKeyNames="appID" SelectMethod="Ex_Application_GetData">
<ItemTemplate>    
...    
...
...
</ItemTemplate>
</asp:ListView>

我在selectmethod背后的代码如下所示:

public IQueryable<Ex_Application> Ex_Application_GetData([QueryString("appId")]int applicationID)
{
    DatabaseEntities db = new DatabaseEntities();
    var query = (from e in db.Ex_Application
                 where e.appID == applicationID
                 select e);            

    if (query.Count() == 0)
    {
        Label_ErrorMessage.Text = "There was a problem retrieving the application from the database, please contact a site admin";
        Label_ErrorMessage.Visible = true;

        Logger.LoggerError(Utility.GetUsername_string(),
              "No Application found",
              Request.RawUrl.ToString(),
              "UcApplicationDisplay Ex_Application_GetData",
              "No application found for appID " + applicationID
              );
    }

    return query;
}

Ex_Application有一个属性UserID,我希望在将对象返回到控件之前将此整数传递给另一个方法,但我似乎无法访问该属性,我必须遗漏一些简单的东西。 / p>

有人有任何建议吗?

我基本上希望我的方法看起来像这样:

        public IQueryable<Ex_Application> Ex_Application_GetData([QueryString("appId")]int applicationID)
    {
        DatabaseEntities db = new DatabaseEntities();
        var query = (from e in db.Ex_Application
                     where e.appID == applicationID
                     select e);            

        if (query.Count() == 0)
        {
            Label_ErrorMessage.Text = "There was a problem retrieving the application from the database, please contact a site admin";
            Label_ErrorMessage.Visible = true;

            Logger.LoggerError(Utility.GetUsername_string(),
                  "No Application found",
                  Request.RawUrl.ToString(),
                  "UcApplicationDisplay Ex_Application_GetData",
                  "No application found for appID " + applicationID
                  );

            return null;
        }

        ***someOtherMethod(query.UserID);***

        return query;
    }

我用Google搜索,似乎无法找到答案,但也许我使用的搜索字词不正确...

0 个答案:

没有答案