首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >加入EntityDataSource?

加入EntityDataSource?
EN

Stack Overflow用户
提问于 2013-05-28 20:29:49
回答 1查看 1.9K关注 0票数 1

我将一个GridView绑定到以下EntityDataSource:

代码语言:javascript
复制
<asp:EntityDataSource ID="sessionQuery" runat="server" 
    ConnectionString="name=encoreEntities" DefaultContainerName="encoreEntities"
    EnableFlattening="False" EntitySetName="sessions" Include="user, user.person" 
    Where="it.lastactivity > @NowMinusXMins" OrderBy="it.lastactivity desc" >   
    <WhereParameters>
        <asp:Parameter Name="NowMinusXMins" Type="DateTime" />
    </WhereParameters>
</asp:EntityDataSource>

这个很好用。

我有另一个名为SessionHistory的表,它有一个进入会话的外键。此表跟踪会话期间访问的页面。我希望将会话实体链接到SessionHistory中的最新记录,并在GridView中显示页面。

连接应该是这样的:

选择*从会话的s.sessionid =(通过lastactivitydate从会话历史顺序中选择顶级1 sessionid )

我可以在这篇文章中这样做:EntityDataSource query inner join,但是,我试图保留EF关系,以便在我的Gridview中引用它们(例如。( session.user.username,session.user.person.lastname等)

有办法这样做吗?

EN

回答 1

Stack Overflow用户

发布于 2013-05-28 20:46:04

下面是一个真实的示例,其中有、两个表、三个导航属性

  • lm_m_location_type表定义了一个位置(国家、城市、州等)
  • lm_m_location表包含在父/子层次结构中排列的位置的行(例如美国->佛罗里达->坦帕、奥兰多、迈阿密)。

Relationships

  • lm_m_location_type定义了零到多个位置。
  • lm_m_location可以有零到多个子位置。
  • lm_m_location可以有零个或一个父位置。

导航属性(从EntityFramework到Edit )

  • Name=ChildLocations NavigationProperty Relationship=DB.fk_child_loc FromRole=lm_m_location ToRole=lm_m_location1
  • Name=ParentLocation NavigationProperty Relationship=DB.fk_parent_loc FromRole=lm_m_location1 ToRole=lm_m_location
  • Name=LocationType NavigationProperty Relationship=DB.fk_loc_type FromRole=lm_m_location ToRole=lm_m_location_type

代码示例:用于访问位置并包括父行、子行和位置类型行的

代码语言:javascript
复制
//
// code from the controller
//

public ActionResult getLocation()
{
    var lm_m_location = db.lm_m_location
        .Include("ParentLocation")
        .Include("ChildLocations")
        .Include("LocationType")
        .Where(t => t.parent_location_id == LinkDB.MvcApplication.Location.Current.id);

    return View(lm_m_location.ToList());
}

//
// code from the view that accesses each of the included tables
//
@model IEnumerable<LinkDBuilder.Models.lm_m_location>

@Html.DisplayFor(modelItem => item.description)
@Html.DisplayFor(modelItem => item.ParentLocation.description)
@Html.DisplayFor(modelItem => item.LocationType.description)

    // inside a loop of the child locations
    @Html.DisplayFor(modelItem => item.ChildLocations.description)

    // just to show we could drill back to the grand parent location if we wanted
    // of course we would make sure there was a value first in production code
    @Html.DisplayFor(modelItem => item.ParentLocation.ParentLocation.description)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16800924

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档