2

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.

rism
  • 11,932
  • 16
  • 76
  • 116
  • I didn't know you could use `join` in LINQ. That's cool! **What error do you get when you try to compile?** – dwerner Mar 19 '12 at 02:36
  • So it's going to be something in your `new` set of initializers `{}` – dwerner Mar 19 '12 at 02:40
  • hi, Linq is cool for sure. I've amended the question to include the message. – rism Mar 19 '12 at 02:41
  • Do all of the members in the `new ItemMovementEntry() {...};` part of the statement exist as accessible members of ItemMovementEntry? Could you post the interface for that class? – dwerner Mar 19 '12 at 02:43
  • Yeah its the complex types. (DispatchedPhase.DocumentDate, DispatchedPhase.DocumentLKey, etc) Not sure how to rewrite it though. – rism Mar 19 '12 at 02:43
  • Ahh I see. Thanks, it just wasn't clicking. – dwerner Mar 19 '12 at 02:44
  • 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. – dwerner Mar 19 '12 at 02:44
  • I could select new anonymous type yes, but it's not what I want to do. I'd like to know if this an an out and out limitation or just requires a different sequence of code statements in order to compile. I'm surprised I haven't struck it before. – rism Mar 19 '12 at 02:49

2 Answers2

1

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>();
    }
Jorge Y. C. Rodriguez
  • 3,394
  • 5
  • 38
  • 61
rism
  • 11,932
  • 16
  • 76
  • 116
0

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.

dwerner
  • 6,462
  • 4
  • 30
  • 44
  • I could select new anonymous type yes, but it's not what I want to do. I'd like to know if this an an out and out limitation or just requires a different sequence of code statements in order to compile. I'm surprised I haven't struck it before. – rism Mar 19 '12 at 02:56