规划步骤 3:确定每个实体的标识符

上次修改时间: 2010年4月19日

适用范围: SharePoint Server 2010

对于每个外部内容类型,必须指定用于唯一标识该外部内容类型的实例的字段。如果没有标识符,Business Data Connectivity (BDC) Service 将无法唯一标识实体实例。后端应用程序方法返回的数据只是没有标识符的 Blob 数据。只有返回的数据具有标识符,这些数据在 BDC 中才有语义意义,只有这样您才能对这些实体执行操作、进行搜索和爬网。

例如,SampleWebService 代理中的 Customer 类包含一个名为 CustomerID 的字段,该字段唯一标识一个客户实例。因此,CustomerID 可用作 Customer 外部内容类型的标识符。以下是 Web 服务代理中的 Customer 类定义。

public partial class Customer {
    
    private string customerIDField;
    
    private string nameField;
    
    private System.Nullable<long> workPhoneNumberField;
    
    private System.Nullable<long> mobilePhoneNumberField;
    
    private string industryField;
    
    private string webSiteField;
    
    private CustomerAddress[] customerAddressesField;
    
    private string parentCustomerIDField;
    
    /// <remarks/>
    public string CustomerID {        get {            return this.customerIDField;        }        set {            this.customerIDField = value;        }
    }
    
    /// <remarks/>
    public string Name {
        get {
            return this.nameField;
        }
        set {
            this.nameField = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
    public System.Nullable<long> WorkPhoneNumber {
        get {
            return this.workPhoneNumberField;
        }
        set {
            this.workPhoneNumberField = value;
        }
    }
    
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
    public System.Nullable<long> MobilePhoneNumber {
        get {
            return this.mobilePhoneNumberField;
        }
        set {
            this.mobilePhoneNumberField = value;
        }
    }
    
    /// <remarks/>
    public string Industry {
        get {
            return this.industryField;
        }
        set {
            this.industryField = value;
        }
    }
    
    /// <remarks/>
    public string WebSite {
        get {
            return this.webSiteField;
        }
        set {
            this.webSiteField = value;
        }
    }
    
    /// <remarks/>
    public CustomerAddress[] CustomerAddresses {
        get {
            return this.customerAddressesField;
        }
        set {
            this.customerAddressesField = value;
        }
    }
    
    /// <remarks/>
    public string ParentCustomerID {
        get {
            return this.parentCustomerIDField;
        }
        set {
            this.parentCustomerIDField = value;
        }
    }
}
    public Customer(string id, string name, uint? workphone, uint? mobilephone, string industry, string website, CustomerAddress[] custaddresses, string parentid)
    {
        this.CustomerID = id;
        this.Name = name;
        this.WorkPhoneNumber = workphone;
        this.MobilePhoneNumber=mobilephone;
        this.Industry = industry;
        this.WebSite = website;
        this.CustomerAddresses = custaddresses;
        this.ParentCustomerID = parentid;
    }
}

但是,对于 LineItem 类,OrderID 和 ProductID 共同标识 LineItem 示例。因此,可声明 OrderID 和 ProductID 作为 LineItem 外部内容类型的标识符,如以下代码示例中所示。

public partial class LineItem {
    
    private string orderIDField;
    
    private string productIDField;
    
    private string productNameField;
    
    private int orderQtyField;
    
    private decimal unitPriceField;
    
    private decimal lineTotalField;
    
    /// <remarks/>
    public string OrderID {        get {            return this.orderIDField;        }        set {            this.orderIDField = value;        }    }
    
    /// <remarks/>
    public string ProductID {        get {            return this.productIDField;        }        set {            this.productIDField = value;        }    }
    
    /// <remarks/>
    public string ProductName {
        get {
            return this.productNameField;
        }
        set {
            this.productNameField = value;
        }
    }
    
    /// <remarks/>
    public int OrderQty {
        get {
            return this.orderQtyField;
        }
        set {
            this.orderQtyField = value;
        }
    }
    
    /// <remarks/>
    public decimal UnitPrice {
        get {
            return this.unitPriceField;
        }
        set {
            this.unitPriceField = value;
        }
    }
    
    /// <remarks/>
    public decimal LineTotal {
        get {
            return this.lineTotalField;
        }
        set {
            this.lineTotalField = value;
        }
    }
}

然而,有可能出现某个外部内容类型无需标识符的情况,例如,SampleWebService 代理中的 Address 外部内容类型。Address 外部内容类型没有标识符,因为我们只希望显示客户的地址列表。这意味着它只是 Blob 数据;您无法对该外部内容类型运行操作,无法使用外部内容类型实例选取器,无法与该外部内容类型关联,无法对该外部内容类型进行搜索或爬网等。

public partial class CustomerAddress {
    
    private CustomerStreet streetField;
    
    private string cityField;
    
    private States stateProvinceField;
    
    private string countryRegionField;
    
    private string postalCodeField;
    
    /// <remarks/>
    public CustomerStreet Street {
        get {
            return this.streetField;
        }
        set {
            this.streetField = value;
        }
    }
    
    /// <remarks/>
    public string City {
        get {
            return this.cityField;
        }
        set {
            this.cityField = value;
        }
    }
    
    /// <remarks/>
    public States StateProvince {
        get {
            return this.stateProvinceField;
        }
        set {
            this.stateProvinceField = value;
        }
    }
    
    /// <remarks/>
    public string CountryRegion {
        get {
            return this.countryRegionField;
        }
        set {
            this.countryRegionField = value;
        }
    }
    
    /// <remarks/>
    public string PostalCode {
        get {
            return this.postalCodeField;
        }
        set {
            this.postalCodeField = value;
        }
    }
}

后续步骤

规划步骤 4:确定每个实体所需的筛选器