Domanda

I was initializing the object in the code below using simple properties but then refactored elsewhere such that DispatchedDocumentDate became DispatchedPhase.DocumentDate. I did this because there is also sold and picked classes using precisely the same properties.

So now in a referencing assembly I have this code which doesn't compile:

 public List<ItemMovementEntry> FillItemDispatchMovements(IEntityDateRange imqp)
        {
            var f = from detail in this.Context.DispatchDetails
                    join header in this.Context.Dispatches on detail.ClientOrderNumber equals header.ClientOrderNumber
                    where (detail.ProductCode == imqp.ItemKey)
                     && (header.DateOrdered >= imqp.StartDate)
                     && (header.DateOrdered <= imqp.EndDate)
                    orderby header.DateOrdered descending
                    select new ItemMovementEntry(ItemMovementEntryKind.Dispatch)
                    {
                        DispatchedPhase.DocumentDate = ((header.DateOrdered.HasValue) ? header.DateOrdered.Value : new DateTime(1900, 1, 1)),
                        DispatchedPhase.DocumentLKey = header.ClientOrderNumber,
                        MaterialItemLkey = detail.ProductCode,
                        DispatchedPhase.MovementDeltaQty = ((detail.QuantityDelivered.HasValue) ? (-1) * detail.QuantityDelivered.Value : 0),
                        DispatchedPhase.Comment = string.Empty,
                        JournalType = "DISPATCHED",
                    };
            return f.ToList<ItemMovementEntry>();
        }

I get an :

Invalid initializer member declarator

error message.

Hopefully the intent is clear but I'm not sure how to rewrite. I Googled and got something about Let but it was still unclear.

È stato utile?

Soluzione

At this point I will go with adding an extra constructor to the ItemMovementEntry class specifically to deal with this problem.

   public ItemMovementEntry(ItemMovementEntryKind comparerMovementKind,
                    DateTime documentDate,
                    string documentLKey,
                    string materialItemKey,
                    int movementDeltaQty,
                    string comment)
            : this(comparerMovementKind)
        {
            ItemMovementEntryPhase p = null;
            switch (comparerMovementKind)
            {
                case ItemMovementEntryKind.Sales:
                    p = this.SoldPhase;
                    break;
                case ItemMovementEntryKind.Picking:
                    p = this.PickedPhase;
                    break;
                case ItemMovementEntryKind.Dispatch:
                    p = this.DispatchedPhase;
                    this.JournalType = "DISPATCHED";
                    break;
            }
            p.DocumentDate = documentDate;
            p.DocumentLKey = documentLKey;
            this.MaterialItemLkey = materialItemKey;
            p.MovementDeltaQty = movementDeltaQty;
            p.Comment = comment;
        }

    public List<ItemMovementEntry> FillItemDispatchMovements(IEntityDateRange imqp)
    {
        var f = from detail in this.Context.DispatchDetails
                join header in this.Context.Dispatches on detail.ClientOrderNumber equals header.ClientOrderNumber
                where (detail.ProductCode == imqp.ItemKey)
                 && (header.DateOrdered >= imqp.StartDate)
                 && (header.DateOrdered <= imqp.EndDate)
                orderby header.DateOrdered descending
                select new ItemMovementEntry(ItemMovementEntryKind.Dispatch,
                    ((header.DateOrdered.HasValue) ? header.DateOrdered.Value : new DateTime(1900, 1, 1)),
                    header.ClientOrderNumber,
                    detail.ProductCode,
                    ((detail.QuantityDelivered.HasValue) ? (-1) * detail.QuantityDelivered.Value : 0),
                    string.Empty){};
        return f.ToList<ItemMovementEntry>();
    }

Altri suggerimenti

Could you build properties in the immediate type that alias set? e.g. where you hold the complex type, make a property that has a setter for the child entity's property that you'd like to set.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top