EDI.Net icon indicating copy to clipboard operation
EDI.Net copied to clipboard

Repeating Group of segments

Open ogmiosnetworks opened this issue 6 years ago • 2 comments

I have a repeating group of segments that I am not sure how to create the classes for.

ISA*<this works fine>
GS*<this works fine>
ST*<this works fine>
N7*<data>
GA*<data>
N7*<data>
GA*<data>
SE*<this works fine>
GE*<this works fine>
IEA*<this works fine>

I can have an arbitrary number of N7 and GA segments and each N7 is related to the GA below it so I would like to put each N7/GA group into the same containing class. I have tested my classes out separately (just an N7 and then just a GA) and they work fine individually, so I think it is the way I am attempting to group them together.

    [EdiSegment, EdiPath("N7")]
    public class MyN7
    {
       // my fields
    }

    [EdiSegment, EdiPath("GA")]
    public class MyGa
    {
       // my fields
    }

    [EdiSegmentGroup("N7", "GA")]
    public class MyGroup
    {
          public MyN7 theN7 {get;set;}
          public MyGa theGa {get;set;}
    }

    [EdiMessage]
    public class TransactionSetHeader
    {
        // my ST stuff
       public List<MyGroup> TheN7AndGaGroups {get;set;}
       // my SE stuff
    }

There are no parse errors but while the GA segments will all parse fine, all of the N7 segments are always null. If I change the TransactionSetHeader to just have 1 instance of an N7 and a GA and modify my input file to only have 1 N7/GA pair, it will parse happily.

I have tried to put all of the N7 / GA fields into the same class (parse failure - it couldn't find a GA on the stack) and several other variants.

If I use this and serialize it to a file (instead of reading it in), it does serialize as expected.

Any suggestions?

Thanks

ogmiosnetworks avatar Jan 14 '19 19:01 ogmiosnetworks

Hi in order for this to work you have to map segment groups to a subclass of the first segment in the sequence. Have a look here https://github.com/indice-co/EDI.Net/issues/32#issuecomment-281741174 for a detailed explanation. Also look at this example (although EDIFact the same principles apply). Related to #97

cleftheris avatar Jan 15 '19 13:01 cleftheris

Hi have you managed to overcome this issue? You mainly have to do the following

    [EdiSegment, EdiPath("N7")]
    public class MyN7
    {
       // my fields
    }

    [EdiSegment, EdiPath("GA")]
    public class MyGa
    {
       // my fields
    }

    [EdiSegmentGroup("N7", "GA")]
    public class MyGroup : MyN7
    {
          public MyGa theGa {get;set;}
    }

    [EdiMessage]
    public class TransactionSetHeader
    {
        // my ST stuff
       public List<MyGroup> TheN7AndGaGroups {get;set;}
       // my SE stuff
    }

cleftheris avatar Feb 14 '19 08:02 cleftheris