冠军

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

使用客户端模型编程处理外部列表

原文名称:SP 2010: Programmatically work with External Lists (BCS) using the Client Object Model 

原文地址:http://www.zimmergren.net/archive/2010/01/21/sp-2010-programmatically-work-with-external-lists-bcs-using-the-client-object-model.aspx

介绍

这是这个系列的第三篇。

  • 在 SharePoint2010 中使用 BCS (Business Connectivity Services )
  • 在 SharePoint2010 中编程方式使用 BCS
  • 使用客户端模型编程处理外部列表
  • 在前几篇文章中,我讨论了如何简单地通过外部列表来处理数据,这篇文章,我将会讨论如何通过客户端对象模型来访问 BCS 中的数据。

    使用客户端对象模型读取外部列表数据

    在这个系列的前面文章中,我讨论了通过 SharePoint 2010 服务器端的 API 是如何简单地处理数据。

    现在,我们将会讨论通过客户端的对象模型来处理同样的问题。

    底层的数据

    我们仍然使用前一篇文章中的数据。

    我设计了一个 WinForm 应用程序,使用 Silverlight 对象模型或者 JavaScript 客户端对象模型。

    当点击名为 Get External Data 的按钮时,将会使用客户端对象模型来从外部列表中获取数据,然后显示在 DataGridView 中。

    代码

    复制代码
    // Define the Client Context (as defined in your textbox)
    SP.ClientContext context = new SP.ClientContext(tbSite.Text);
    SP.Web site
    = context.Web;

    var ProductList
    = site.Lists.GetByTitle(tbList.Text);

    SP.CamlQuery camlQueryAwesomeness
    = new SP.CamlQuery();

    IQueryable
    <SP.ListItem> productItems =
    ProductList.GetItems(camlQueryAwesomeness);

    IEnumerable
    <SP.ListItem> externalList =
    context.LoadQuery(productItems);

    // This is where we actually execute the request against the server!
    context.ExecuteQuery();

    // Retrieve the products from the product list using some fancy LINQ
    var productListData = from product in externalList
    select
    new
    {
    // We're never pointing to the field at the 0-index
    // because it's used by the BDC Identity itself. Hence our elements start at 1.
    ProductID = product.FieldValues.ElementAt(1).Value.ToString(),
    ProductName
    = product.FieldValues.ElementAt(2).Value.ToString(),
    ProductDescription
    = product.FieldValues.ElementAt(3).Value.ToString()
    };

    // Simply clear the rows and columns of the GridView
    gvProducts.Rows.Clear();
    gvProducts.Columns.Clear();

    // Add the columns we need (ProductID, Name, Description)
    gvProducts.Columns.Add("ProductID", "ProductID");
    gvProducts.Columns.Add(
    "Name", "Product Name");
    gvProducts.Columns.Add(
    "Description", "Product Description");
    foreach (var product in productListData)
    {
    // For each product in the list, add a new row to the GridView
    gvProducts.Rows.Add(
    product.ProductID,
    product.ProductName,
    product.ProductDescription
    );
    }
    复制代码

    参考:

  • Getting Started with the Client Object Model in SharePoint 2010
  • Getting Started with Business Connectivity Services in SharePoint 2010
  • 总结和下载

    在这个系列中,我通过三篇文章演示了如何创建一个 BCS 数据源,然后通过服务器端对象或者客户端对象从中获取数据。

    值得注意的是,这只是一个 Bete 版的演示。

    完整的 Visual Studio 2010 项目下载: [ Zimmergren.SP2010.ClientOM.BCS.zip ]

    posted on   冠军  阅读(668)  评论(1编辑  收藏  举报

    编辑推荐:
    · AI与.NET技术实操系列(二):开始使用ML.NET
    · 记一次.NET内存居高不下排查解决与启示
    · 探究高空视频全景AR技术的实现原理
    · 理解Rust引用及其生命周期标识(上)
    · 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
    阅读排行:
    · DeepSeek 开源周回顾「GitHub 热点速览」
    · 物流快递公司核心技术能力-地址解析分单基础技术分享
    · .NET 10首个预览版发布:重大改进与新特性概览!
    · AI与.NET技术实操系列(二):开始使用ML.NET
    · 单线程的Redis速度为什么快?
    点击右上角即可分享
    微信分享提示