暴露 ria 服务中的关联实体 [英] exposing Associated entities in ria services

查看:24
本文介绍了暴露 ria 服务中的关联实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读此链接:-

RIA 服务:实体框架参考实体

并在元数据类以及我的域服务查询中添加了[Include].

and added [Include] in metadata class as well as in my domain service query.

在我的客户端,我的 Albums 实体中有一个名为 Photos 的导航属性.但是它是 EntityCollection 类型,我不知道如何迭代它.它没有 get 方法,甚至索引也不适用于它.我尝试了以下方法:-

On my client side i have a navigation property named Photos in my Albums entity. However it is of type EntityCollection and i don't know how to iterate over it. It has no get method and even indexing doesn't apply on it. I have tried the following :-

albums.photos[0]

但它不起作用.谁能告诉我如何遍历相册实体中的照片集?

but it doesn't work. Can anybody tell me how do i iterate over that photos collection in my albums entity ?

提前致谢:)

推荐答案

因此,在您的相册类的元数据中,您有如下内容:

So, in the metadata for your Albums class you have something like:

[MetadataTypeAttribute( typeof(Album.AlbumMetadata ) )]
public partial class Album
{
  internal sealed class AlbumMetadata
  {
    private AlbumMetadata ()
    { }

    [Include]
    public EntityCollection<Photo> Photos { get; set; } 
}

在您的域服务中,您将拥有以下内容:

In your domain service you would have something like:

    public IEnumerable<Album> GetAlbums ()
    {
        var albums = from a in ObjectContext.Albums.Include( "Photos" )
                     orderby a.AlbumId descending
                     select a;
        return albums;
    }

在您的客户端代码中,您可以执行以下操作:

In you clientside code you could then do:

public void LoadAlbumsWithPhotos ()
{
  LoadOperation<Album> albumLoader = Context.Load( Context.GetAlbumsQuery() );
  albumLoader.Completed += ( s, e ) =>
    {
       _albumStore = ( s as LoadOperation<Album> ).Entities.ToList();
    };
}

然后可以通过以下方式检索照片:

Photos could then be retrieved by:

var photos = _albumStore.First().Photos.Select( p => p);

希望这会有所帮助.

这篇关于暴露 ria 服务中的关联实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆