枚举OData服务数据上下文

时间:2019-05-20 04:07:51

标签: c# odata enumerate

我有一个OData服务,该服务返回共享点列表的列表。 我无法枚举此列表。

是否有可能枚举它以便在foreach循环中循环遍历此Context中的列表?

public class ODService
{
    private DataContext _Context;
    private NetworkCredential _nc;

    public DataContext Context { get { return _Context; } }

    /// <summary>
    /// Constructor creates the context for access to sharepoint
    /// </summary>
    /// <param name="UserName">Service Account User Name</param>
    /// <param name="Password">Service Account Password</param>
    /// <param name="uri">Service uri</param>
    public ODService(string UserName, string Password, string uri)
    {
        SetNetworkCredentials(UserName, Password);
        SetContext(uri);
    }

    private void SetContext(string uri)
    {
        _Context = new DataContext(new Uri(uri));
        _Context.Credentials = _nc;
        _Context.MergeOption = MergeOption.NoTracking;

    }

    private void SetNetworkCredentials(string UserName, string Password)
    {
        _nc = new NetworkCredential(UserName, Password);
    }
}

1 个答案:

答案 0 :(得分:0)

知道了:

    public IList<string> EntityList()
    {
        IList<string> PropertyList = new List<string>();

        var Properties = typeof(DataContext).GetProperties();
        foreach (var property in Properties)
        {
            PropertyList.Add(property.Name);
        }

        return PropertyList;
    }