ServiceStack,OrmLite问题保存相关实体

时间:2014-05-23 23:19:34

标签: ormlite-servicestack

我已经搜索了一段时间寻找这个问题的解决方案但没有找到任何东西。

我正在尝试将客户端DTO及其相关的联系人DTO发布到我的ServiceStack Web服务,但是我收到了错误消息。我跟着位于here的OrmLite测试。

我的DTO:

public partial class Client {
    [AutoIncrement]
    public int ID { get; set; }
    public string Street { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string ZipCode { get; set; }
    public decimal? Latitude { get; set; }
    public decimal? Longitude { get; set; }
    public string HomePhoneAreaCode { get; set; }
    public string HomePhoneExchange { get; set; }
    public string HomePhoneNumber { get; set; }
    public string HomeFaxAreaCode { get; set; }
    public string HomeFaxExchange { get; set; }
    public string HomeFaxNumber { get; set; }
    public string KeyNumber { get; set; }
    public string AlarmCode { get; set; }
    public string GarageDoorCode { get; set; }
    public string MyAPCUsername { get; set; }
    public string MyAPCPassword { get; set; }
    public bool IsActive { get; set; }
    public string Notes { get; set; }

    [Reference]
    public List<Contact> Contacts { get; set; }
}

public partial class Contact {
    [AutoIncrement]
    public int ID { get; set; }
    public int ClientID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string WorkPhoneAreaCode { get; set; }
    public string WorkPhoneExchange { get; set; }
    public string WorkPhoneNumber { get; set; }
    public string MobilePhoneAreaCode { get; set; }
    public string MobilePhoneExchange { get; set; }
    public string MobilePhoneNumber { get; set; }
    public bool CanSMS { get; set; }
    public string PersonalEmail { get; set; }
    public string WorkEmail { get; set; }
    public string AlternateEmail { get; set; }
    public int Ordinal { get; set; }

    [Reference]
    public Client Client { get; set; }
}

在我的服务中:

    public int Post(Client client) {
        Db.Save(client, references: true);

        return client.ID;
    }

我的测试代码:

var newClient = new Client {
    Street = "1234 Any Avenue",
    City = "Gorham",
    State = "ME",
    ZipCode = "22222",
    HomePhoneAreaCode = "123",
    HomePhoneExchange = "456",
    HomePhoneNumber = "7890",
    HomeFaxAreaCode = "098",
    HomeFaxExchange = "765",
    HomeFaxNumber = "4321",
    KeyNumber = "99",
    AlarmCode = "1234",
    GarageDoorCode = "abcd",
    IsActive = true,
    Notes = "These are the notes for the new client.",

    Contacts = new List<Contact>() {
        new Contact { FirstName = "John", LastName = "Doe", PersonalEmail = "john.doe@gmail.com", CanSMS = true, Ordinal = 1 },
        new Contact { FirstName = "Jane", LastName = "Smith", PersonalEmail = "jane.smith@gmail.com", CanSMS = false, Ordinal = 2 }
    },
};


// POST entity 
int newClientID = serviceClient.Post<int>(newClient);

最后一行产生错误 - WebServiceException,消息“无法找到'ClientId'属性类型'联系人'”

我尝试过Reference,References和ForeignKey属性的不同组合无济于事。

任何帮助都将不胜感激。

谢谢,

0 个答案:

没有答案