在部分实体类中添加构造函数后出错(Silverlight应用程序)

时间:2014-11-07 09:16:03

标签: c# silverlight service ria

我有问题! 我正在使用ria服务开发silverlight应用程序。当我在实体分部类中添加aditional constuctor时,我无法初始化类对象,如:

select new VaultCashOrderQuantity
{
    VaultCashOrderQuantitiesId = Guid.NewGuid(),
    VaultCashOrderId = cashOrder.VaultCashOrderId,
    VaultCurrency = currency,
    VaultCurrencyCode = currency.VaultCurrencyCode,
    VaultCurrencyId = currency.VaultCurrencyId,
    VaultCurrencyDenomination = denomination,
    VaultCurrencyDenominationId = denomination.VaultCurrencyDenominationId,
    Denomination = denomination.Denomination,
    Quantity = 0,
    Summ = 0,
    Amount = 0,
})

然后我添加了无参数构造函数。这是我在分部类中的两个新构造函数:

public partial class VaultCashOrderQuantity
{
    public VaultCashOrderQuantity() { }
    public VaultCashOrderQuantity(CPCashOrderQuantity quantity, Guid cashOrderId)
    {
        VaultCashOrderQuantitiesId = Guid.NewGuid();
        VaultCashOrderId = cashOrderId;
        Denomination = quantity.Denomination;
        Quantity = quantity.Quantity;
        VaultCurrencyId = quantity.VaultCurrencyId;
        //VaultCurrency = quantity.VaultCurrency;
        VaultCurrencyDenominationId = quantity.VaultCurrencyDenominationId;
        //VaultCurrencyDenomination = quantity.VaultCurrencyDenomination;
        Summ = quantity.Summ;
        Amount = quantity.Amount;
    }

在应用程序构建时,我收到了错误消息:

  

类型'Vaults.Data.Models.VaultCashOrderQuantity'已经定义了一个名为'VaultCashOrderQuantity'的成员,其参数类型相同

为什么我收到此错误消息?如何解决这种情况?

1 个答案:

答案 0 :(得分:0)

我没有测试过相同的例子,但你是否试过编写没有de default构造函数的部分类?

像这样:

public partial class VaultCashOrderQuantity

{

    public VaultCashOrderQuantity(CPCashOrderQuantity quantity, Guid cashOrderId)
    {
        VaultCashOrderQuantitiesId = Guid.NewGuid();
        VaultCashOrderId = cashOrderId;
        Denomination = quantity.Denomination;
        Quantity = quantity.Quantity;
        VaultCurrencyId = quantity.VaultCurrencyId;
        //VaultCurrency = quantity.VaultCurrency;
        VaultCurrencyDenominationId = quantity.VaultCurrencyDenominationId;
        //VaultCurrencyDenomination = quantity.VaultCurrencyDenomination;
        Summ = quantity.Summ;
        Amount = quantity.Amount;
    }

}

如果它不起作用,也许你可以尝试在ria服务类中使用这个构造函数。

在最后一种情况下,您可以创建一个方法并在类初始化后使用它。

我现在无法测试,这就是我试图帮助这些选项的原因,让我知道会发生什么。