什么和#34; Union或Concat中的类型以不同的顺序分配成员"意思?

时间:2016-06-21 19:41:13

标签: c# wcf xamarin.android

以下是什么意思?

  

Union或Concat中的类型具有按不同顺序分配的成员

我试图连接两个子类并在列表中对它们进行排序,但是我得到了这个错误。我的代码看起来像这样。我更喜欢对错误的解释,但对此的解决方案也将受到赞赏。

    public List<InterfaceItem> GetTransactions(string id)
    {
        DataClasses1DataContext context = new DataClasses1DataContext();

        var tollQuery = from t in context.Tolls
                        where t.account_id.Equals(id)
                        select new TollTest { Date = t.status_time, Amount = t.fee, Plate = t.plate_id };
        var paymentQuery = from p in context.Payments
                           where p.account_id.Equals(id)
                           select new PaymentTest { Date = p.status_time, Amount = p.payment1, PaymentMethod = p.credit_type };

        IQueryable<InterfaceItem> toll = tollQuery;
        IQueryable<InterfaceItem> payment = paymentQuery;

        var all = (toll.Concat(payment)).ToList();
        return all;
    }

1 个答案:

答案 0 :(得分:0)

从Nikki9696的灵感来看,我想通了。我使用TollTest和PaymentTest作为InterfaceItem的子类。最后,我删除了子类,而是执行了以下操作:

        var tollQuery = from t in context.Tolls
                        where t.account_id.Equals(id)
                        select new InterfaceItem { Date = t.status_time, Amount = t.fee, PaymentMethod = null,  Plate = t.plate_id };
        var paymentQuery = from p in context.Payments
                           where p.account_id.Equals(id)
                           select new InterfaceItem { Date = p.status_time, Amount = p.payment1, PaymentMethod = p.credit_type, Plate = null };

只有在我使用基类变量,即

时才能成功使用子类
            var tollQuery = from t in context.Tolls
                        where t.account_id.Equals(id)
                        select new TollTest { Date = t.status_time, Amount = t.fee};
        var paymentQuery = from p in context.Payments
                           where p.account_id.Equals(id)
                           select new PaymentTest { Date = p.status_time, Amount = p.payment1};

因此,如果您遇到此错误,则应确保您具有相同的变量名称,而不仅仅是其类型。