数据源中缺少实体框架 4 导航属性

发布于 2024-11-14 18:23:41 字数 538 浏览 11 评论 0原文

我有包含 3 个表的数据库 - Actors、Films、Actors_Films。其中 2 个表具有多对多关系(Actors 和 Films),该关系使用联结表 (Actors_Films) 进行建模。

我在 Silverlight 应用程序中使用 EF4。我创建了一个 EF 模型,edmx 设计器仅显示我的演员和电影实体,但它们每个都有一个到另一个实体的导航属性(演员有电影的导航属性,电影有演员的导航属性) 。

我添加了域服务并构建了项目。以演员为例,我现在想要添加一个视图,其中包含一个数据表单,可以让我循环浏览演员,以及一个数据网格,该数据网格将显示当前所选演员出现过的任何电影。但是,在“数据源”选项卡中,我有包含 2 个实体的域上下文 - 演员和电影。这两个实体仅显示其实际列,导航属性未显示:

Actors ---演员ID ---演员姓名

电影 ---影片ID ---FilmTitle

这是正确的吗?我认为应该显示导航属性。

我的实际应用程序比这更复杂,但这是一个简化的示例,只是为了关注实际问题。

谢谢米克

I have DB that contains 3 tables - Actors, Films, Actors_Films. 2 of the tables have a many-to-many relationship (Actors and Films), which is modelled using a junction table (Actors_Films).

I'm using EF4 in a Silverlight app. I've created a EF model, and the edmx designer shows just my Ac tors and Films entities, but they each have a navigation property to the other entity (Actors has a navigation property of Films, and Films has a navigation property of Actors).

I've added a domain service, and built the project. Using Actors as an example I now want to add a view that contains a dataform that will let me cycle through Actors, and a datagrid that will show any films the currently selected actor has appeared in. However, in the Data source tab, I have a domain context containing 2 entities - Actors and Films. These 2 entities are only showing their actual columns, the navigation properties aren't appearing:

Actors
---ActorID
---ActorName

Films
---FilmID
---FilmTitle

Is this correct? I thought the navigation properties should show up.

My actual application is more complicated than this, but this is a simplified example just to focus on the actual issue.

Thanks

Mick

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

記柔刀 2024-11-21 18:23:41

WCF Ria 服务不支持多对多关系。您必须在 edmx 上有关联表。为了使导航属性显示在客户端上,您必须添加 [Include] 属性以在实体的适当元数据中导航属性。元数据通常在您创建任何 DomainService 时生成。例如,我们有多对多的 ContractPosition 和 OrderPosition 关系:

//ContractPositionsService.metadata.cs
[MetadataTypeAttribute(typeof(ContractPosition.ContractPositionMetadata))]
public partial class ContractPosition
{
    internal sealed class ContractPositionMetadata
    {
        public int ContractPositionId { get; set; }
        [Include]
        public EntityCollection<ContractToOrderLink> ContractToOrderLinks { get; set; }

        ...
    }
//ContractToOrdersLinksService.metadata.cs
[MetadataTypeAttribute(typeof(ContractToOrderLink.ContractToOrderLinkMetadata))]
public partial class ContractToOrderLink
{

    internal sealed class ContractToOrderLinkMetadata
    {
        [Include]
        public ContractPosition ContractPosition { get; set; }

        public int ContractPositionId { get; set; }

        [Include]
        public OrderPosition OrderPosition { get; set; }

        public int OrderPositionId { get; set; }            
    }
}


//OrderPositionsService.metadata.cs
[MetadataTypeAttribute(typeof(OrderPosition.OrderPositionMetadata))]
public partial class OrderPosition
{               
    internal sealed class OrderPositionMetadata
    {
        public int OrderPositionId { get; set; }        

        [Include]
        public EntityCollection<ContractToOrderLink> ContractToOrderLinks { get; set; }

        ...
    }
}

WCF Ria Services don't support Many To Many Relation. You must have association table on edmx. In order that Navigate properties appear on client you must add [Include] attribute to navigate property in apropriate metadata of Entity. The metadata usually generated when you create any DomainService. For example, we have relation many to many ContractPosition and OrderPosition:

//ContractPositionsService.metadata.cs
[MetadataTypeAttribute(typeof(ContractPosition.ContractPositionMetadata))]
public partial class ContractPosition
{
    internal sealed class ContractPositionMetadata
    {
        public int ContractPositionId { get; set; }
        [Include]
        public EntityCollection<ContractToOrderLink> ContractToOrderLinks { get; set; }

        ...
    }
//ContractToOrdersLinksService.metadata.cs
[MetadataTypeAttribute(typeof(ContractToOrderLink.ContractToOrderLinkMetadata))]
public partial class ContractToOrderLink
{

    internal sealed class ContractToOrderLinkMetadata
    {
        [Include]
        public ContractPosition ContractPosition { get; set; }

        public int ContractPositionId { get; set; }

        [Include]
        public OrderPosition OrderPosition { get; set; }

        public int OrderPositionId { get; set; }            
    }
}


//OrderPositionsService.metadata.cs
[MetadataTypeAttribute(typeof(OrderPosition.OrderPositionMetadata))]
public partial class OrderPosition
{               
    internal sealed class OrderPositionMetadata
    {
        public int OrderPositionId { get; set; }        

        [Include]
        public EntityCollection<ContractToOrderLink> ContractToOrderLinks { get; set; }

        ...
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文