Entity Framework 4 Navigation properties missing from Data Sources
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. Usin开发者_StackOverflowg 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
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; }
...
}
}
精彩评论