C# help -> Anyone Got something better? LINQ

Ok, backstory first.

I am working on some automated reporting for our “Certificates of Analysis” when an order is shipped.
We are processing most of this data off of the ShipDtl from the Pack in Customer Shipment Entry.

When the pack is marked shipped, it does the thing, bla bla bla.

Anyway, the ShipDtl has a field for JobNum, and I need it, but the way our system is set up, that field
is not populated.

We populate that in a field on PartLot called V8JobNum_c.
Before you ask, no I didn’t name it. Consultant did on uplift from Vantage.
He didn’t realize we would be using it after that :rofl:

Anyway, I was conversing with @josecgomez about if there was a nifty way to do the join between the pack’s ShipDtl table, and PartLot, while returning only the ShipDtl fields, with the JobNum filled in correctly.

This was the best we could come up with, and neither one of us are real happy with it.

So does anyone have any better ideas? (It works BTW, just want perfection :rofl: )

  var shipDetailWithJob = (from tblShipDetail in packTS.ShipDtl
                            join
                                tblPartLot in Db.PartLot
                                on new { tblShipDetail.LotNum, tblShipDetail.PartNum } equals new {tblPartLot.LotNum, tblPartLot.PartNum }
                            into tblJoin
                            
                            from tblCombined in tblJoin.DefaultIfEmpty()
                            
                            select new {tblShipDetail, tblCombined.V8JobNum_c})
                            .ToList()
                            .Select(x =>
                            {
                                x.tblShipDetail.JobNum = x.V8JobNum_c;
                                return x.tblShipDetail;
                            });

The JobNum is there is you are MTO and you ship directly from jobs. If you ship from inventory, you don’t get that field.

If you are shipping Lot Tracked parts, why not just join the LotNum to the Lot Table and then get the JobNum?

1 Like

Yep, that’s me

we did

I just want it in the dataset in one shot, thought there might be a nicer way.

1 Like

@klincecum Do you even need the V8JobNum? Our lot matches the JobNum by default and I use that for this join for our CofC statement. I also double check with the jobnum since we will do a make direct even though we are not suppsoed to.:frowning:

1 Like

Yes our Jobs != LotNums

1 Like

That would make this more fun.

1 Like

Oh hell, this works, and it’s not slow, I’m just being picky.

In fact I like the technique for complicated stuff.

2 Likes

So if you are just trying to get back to the job that created the lot why don’t you just look it up in the Part Tran record?
I’m assuming you are shipping from inventory so you do your job receive to inventory then ship

What we do for our CoC is take the Lot in the Shopment and do a reverse lookup in part tran for the MFG-STK transaction that tells me the job that lot came from and thus get the information that way

PartTran will be slower.

I don’t think it really matters much where the data come from. I was really just looking for something built in to linq to do what I wanted.

1 Like

My last boss used to say things like “Don’t let perfection be the enemy of good”, that being said id love to see you figure this out.

1 Like

Further explanation on what I’m doing.

I need the qty of a part per job that was shipped on the pack.

The Certificates are sent out by Job.

Just extra info.

Well if me and Jose didn’t find anything better together, and no one is putting up leads, I think I’m gonna have leave this one. I got other stuff to do :rofl:

Good thing the weekend is coming. You can just work on it then. :speak_no_evil:

BAQ?

I know y’all are code addicts…

2 Likes

You know I love me some baqs, but I’ve got a perfectly good dataset right there with 99% of what I need :wink:

Well, not perfectly good…now is it?

:innocent:

How I Met Your Mother Sitcom GIF by Laff

I’m not too good at LINQ, why can’t you have the select as part of your first statement, bring back just tblShipDetail and V8JobNum_c and then do the mutation locally? Its my understanding that the “ToList” is the part that brings all the data back that you don’t want.