【问题标题】:How to create a new contact in Saleslogix Infor CRM using DotNetSDataClient如何使用 DotNetSDataClient 在 Saleslogix Infor CRM 中创建新联系人
【发布时间】:2016-12-13 15:49:30
【问题描述】:

我正在尝试使用 DotNetSDataClient library 在 Infor CRM 中添加新联系人。我试图在 Create 部分下关注this documentation。当我运行示例代码时,我收到错误“需要联系人的帐户”。这是有道理的,因为我相信数据库中的每个联系人都必须与一个帐户相关联。我修改了代码以指定现有帐户,但现在我收到错误“我们很抱歉,您遇到了错误。如果适用,请重试。”带有内部异常,“删除服务器返回错误:(500) 内部服务器错误。”

这是我的代码。

public void someFunction(){
    var client = new SDataClient("https://domain/sdata/slx/dynamic/-/")
    {
        UserName = "username",
        Password = "password"
    };

    var contact = new Contact
    {
        Account = new Account
        {
            AccountName = "accountName",
            Id = "accountId"
        },
        Address = new Address
        {
            Address1 = "1234 Address",
            City = "someCity",
            PostalCode = "12345",
            State = "ST"
        },
        FirstName = "John",
        LastName = "Doe"
    };

    var contactOptions = new SDataPayloadOptions { Include = "Address" };

    try
    {
        contact = client.Post(contact, null, contactOptions);
    }
    catch (Exception ex)
    {
        var error = ex.Message;
    }
}

[SDataPath("accounts")]
public class Account
{
    [SDataProtocolProperty(SDataProtocolProperty.Key)]
    public string Id { get; set; }

    public string AccountName { get; set; }
    public List<Contact> Contacts { get; set; }
    public string Status { get; set; }
    public string Type { get; set; }
}

[SDataPath("contacts")]
public class Contact
{
    [SDataProtocolProperty(SDataProtocolProperty.Key)]
    public string Id { get; set; }

    public Account Account { get; set; }
    public Address Address { get; set; }
    public string Email { get; set; }
    public string FirstName { get; set; }
    public string FullName { get; set; }
    public string LastName { get; set; }
    public DateTime? ModifyDate { get; set; }
    public string Status { get; set; }
}

[SDataPath("addresses")]
public class Address
{
    [SDataProtocolProperty]
    public string Key { get; set; }
    public string Address1 { get; set; }
    public string Address3 { get; set; }
    public string Address2 { get; set; }
    public string City { get; set; }
    public string CountryCode { get; set; }
    public string Description { get; set; }
    public string PostalCode { get; set; }
    public string State { get; set; }
    public string Street { get; set; }
}

有人知道我做错了什么吗?

【问题讨论】:

    标签: c# .net saleslogix sdata


    【解决方案1】:

    我还在 GitHub 上发布了这个问题,Ryan Farley 提供了答案。我想把它包括在这里,以防其他人需要这个解决方案。

    问题在于库如何序列化数据。这是瑞恩的回应:

    “这里的真正问题是 Account 的 POCO 有一个联系人集合。DotNetSDataClient 将其序列化为 null 而 SData 服务器不喜欢这样。即使将该集合设置为 new List() 也会失败,因为它将被序列化为 []。它应该是这样的

    "Contacts": { "$resources": [] }
    

    当与现有的父实体或相关实体进行 POST 时,SData 预计只会收到 $key 而不会收到任何其他信息。因此,当 Contact 类被序列化时,您应该与联系人数据一起发送的是

    "Account": { "$key":"AXXX00000001" }
    

    仅此而已,但事实并非如此,库正在序列化并发送所有内容。”

    此时,解决方案是创建一个只有id(key)属性的account类。

    [SDataPath("accounts")]
    public class Account
    {
        [SDataProtocolProperty(SDataProtocolProperty.Key)]
        public string Id { get; set; }
    }
    

    在某些时候可能会更新 DotNetSDataClient 库以处理这种情况,但目前这是解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多