I can only read one class

92 Views Asked by At

I am trying to read an EDI file using Edi.net

But I hit a problem when I want to read the next class.

this is a snippet of my file (I splitted into separate lines here, the actual file is just one long line)

UNB+UNOA:1+0935HRB2001101+MOL4267HUBUD00+100930:1549+00000000008914
'UNH+1+LOGMES:1:0:GM
'BGM+992:Z01:ZGM
'DTM+243:1009301549:201
'NAD+MS+GM*DRIVE
'NAD+MR+MOL42670HUBUD00
'SEQ++XXXXXX
'DTM+11:1008291900:201
'DTM+191:100930:101
'TDT+20++00+:::HOEGH TRADER++00000000
'LOC+Z03+KRDAT10
'LOC+8+HUBUD00

What I am trying to accomplish is to create a class Heading, and this class will contain other classes called UNB, UNH, BGM, DTM, and so on

so it looks like this

enter image description here

Notice that class UNB is populated, but class UNH is NULL

How should I design my classes so both UNB and UNH will be filled. And off course also BGM, DTM, NAD, and so on...

I found this answer and I tried it, but it did not solve my problem.

This is the code I used

public class Interchange
{
    public HeadingSection HeadingSection { get; set; }
    public Quote QuoteMessage { get; set; }
}

[EdiMessage]
public class Quote
{
    public List<VehicleRecord> Vehicles { get; set; }
}

[EdiElement, EdiPath("UNB/*")]
public class HeadingUNB
{
    [EdiValue("X(4)", Mandatory = true, Path = "UNB/0", Description = "Syntax Identifier")]
    public string SyntaxIdentifier { get; set; }

    [EdiValue("9(1)", Path = "UNB/0/1", Mandatory = true)]
    public int SyntaxVersion { get; set; }

    [EdiValue("X(35)", Mandatory = true, Path = "UNB/1")]
    public string SenderIdentificationCode { get; set; }

    [EdiValue("X(35)", Path = "UNB/2/0", Mandatory = true)]
    public string RecipientIdentificationCode { get; set; }

    [EdiValue("9(6)", Path = "UNB/3/0", Format = "ddMMyy", Description = "Shipment Date")]
    [EdiValue("9(4)", Path = "UNB/3/1", Format = "HHmm", Description = "Shipment Time")]
    public DateTime Shipment_Preparation_Date { get; set; }

    [EdiValue("X(14)", Path = "UNB/4/0", Mandatory = true)]
    public string InterchangeControlRef { get; set; }
}

[EdiElement, EdiPath("UNH/*")]
public class HeadingUNH
{
    [EdiValue("X(14)", Mandatory = true, Path = "UNH/0", Description = "Message Reference Number")]
    public string MessageReferenceNumber { get; set; }
}

[EdiSegment, EdiSegmentGroup("UNB", SequenceEnd = "GIN")]
public class HeadingSection
{
    public HeadingUNB UNB { get; set; }
    public HeadingUNH UNH { get; set; }
}
1

There are 1 best solutions below

5
Umair Zafar On

I have no experience with EDI.net but the file you shared should have ' at end of line instead of at start of line